easyui設置datebox默認當前日期,且只能選擇當前日期之前的日期

引言

全心全意爲用戶着想是我們的工作準則,所以細節上馬虎不得!

場景

當我們進行特定的時間條件選擇的時候,會有這樣的情況,就是我們只能查詢今天以及今天以前的信息,我們可以直接擺上去一個時間控件,但是這樣做,會讓用戶有機會出錯,而我們也免不了還要在後面對時間進行驗證。所以我們可以再做的完美一點,就是直接對這個時間控件的可選擇時間上做點手腳。

jsp

<span class="label">計劃運行日期</span>  
    <input name="planRunDt" id="planRunDt" class="easyui-datebox" data-options="editable:false">  

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;   
}  

效果圖



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章