easyui設定datebox預設當前日期,且只能選擇當前日期之前的日期
阿新 • • 發佈:2019-01-01
html程式碼:
<li>
<span class="label">計劃執行日期</span>
<input name="" id="planRunDt" class="easyui-datebox" data-options="editable:false">
</li>
js程式碼:
$('#planRunDt').datebox('setValue', getCurentDateStr()); $('#planRunDt').datebox('calendar').calendar({ validator : function(date){ var now = new Date(); var d1 = new Date(now.getFullYear(),now.getMonth(),now.getDate()); return date <= d1; } }); function getCurentDateStr() { var now = new Date(); var year = now.getFullYear(); //年 var month = now.getMonth() + 1; //月 var day = now.getDate(); //日 var clock = year + "-"; if(month < 10) clock += "0"; clock += month + "-"; if(day < 10) clock += "0"; clock += day; return clock; }
效果: