easyui 时间段校验,开始时间小于结束时间,并且时间间隔不能超过30天


//
对easyui datetimebox的验证,开始时间要小于结束时间

function validateDateTime(beginTimeId,endTimeId,whichTimeId)
{
console.log(
"hello world");
var v1=$('#'+beginTimeId).datetimebox("getValue");
var date1 = new Date(v1);
var v2=$('#'+endTimeId).datetimebox("getValue");
var date2 = new Date(v2);

</span><span style="color: #0000ff;">if</span>(v1==''||v2==''<span style="color: #000000;">)
{
    </span><span style="color: #0000ff;">return</span> <span style="color: #0000ff;">true</span><span style="color: #000000;">;
}    
console.log(date1);
console.log(date2);
</span><span style="color: #0000ff;">if</span>(date1&lt;<span style="color: #000000;">date2)
{
    console.log(date1</span>+"&lt;"+<span style="color: #000000;">date2);
    </span><span style="color: #0000ff;">var</span> diff=<span style="color: #000000;">DateDiff(date1,date2);
    </span><span style="color: #0000ff;">if</span>(diff&gt;30<span style="color: #000000;">)
    {
        $.messager.alert(</span>'提示','时间段不能超过30天!'<span style="color: #000000;">);
        $(</span>'#'+whichTimeId).datetimebox("setValue",""<span style="color: #000000;">);
    }
    </span><span style="color: #0000ff;">return</span> <span style="color: #0000ff;">true</span><span style="color: #000000;">;
}
console.log(date1</span>+"!&lt;"+<span style="color: #000000;">date2);
</span><span style="color: #0000ff;">try</span><span style="color: #000000;">{
    $(</span>'#'+whichTimeId).datetimebox("setValue",""<span style="color: #000000;">);
}</span><span style="color: #0000ff;">catch</span><span style="color: #000000;">(e){
}
</span><span style="color: #0000ff;">try</span><span style="color: #000000;">{
    $(</span>'#'+whichTimeId).datebox("setValue",""<span style="color: #000000;">);
}</span><span style="color: #0000ff;">catch</span><span style="color: #000000;">(e){
}

$.messager.alert(</span>'提示','开始时间要小于结束时间!'<span style="color: #000000;">);

</span><span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #000000;">;       

}

 

示例:

        $('#fssjFrom1').datetimebox({
            onHidePanel: function(date){
                validateDateTime('fssjFrom1','fssjTo1','fssjFrom1');
            }
        });
        $('#fssjTo1').datetimebox({
            onHidePanel: function(date){
                validateDateTime('fssjFrom1','fssjTo1','fssjTo1');
            }
        });

 

posted @ 2017-08-16 13:17  星朝  阅读(1842)  评论(0编辑  收藏  举报