WdatePicker日期控件使用与值获取,以及选择日期完毕触发事件

时间:2021-09-10 15:26:16

HTML:

<!--引入WdaePicker文件-->
<script type="test/javascript" scr="datePicker/WdatePicker.js"></script>
<link rel="stylesheet" type="text/css" href="datePicker/skin/WdatePicker.css"/>
 
<input id="time" type="text" class="Wdate" onclick="WdatePicker({el:$dp.$('time'),dateFmt:'yyyy-MM-DD',onpicked: function () { alert(123) } })"/>
//onpicked: function () { alert(123) } 就是选择日期完毕触发事件

JS:

$dp.$('time').value=getNowFormatDate() ; //设置初始值为当前时间
var time = $dp.$('time').value; //获取值,$dp.$('time')相当于Document.GetElementById



上面使用到的getNowFormatDate() 方法:

//获取当前时间,格式YYYY-MM-DD
    function getNowFormatDate() {
        var date = new Date();
        var seperator1 = "-";
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var strDate = date.getDate();
        if (month >= 1 && month <= 9) {
            month = "0" + month;
        }
        if (strDate >= 0 && strDate <= 9) {
            strDate = "0" + strDate;
        }
        var currentdate = year + seperator1 + month + seperator1 + strDate;
        return currentdate;
    }