WdatePicker日期控件使用與值獲取,以及選擇日期完畢觸發事件

踩過無數坑,調試了很長時間,寫出適合本身需求的方法
需求:沒有查詢按鈕,要求選擇日期後自動觸發查詢事件(只有日期選擇完成後才觸發),

解決方案:代碼以下:
檢索開始時間:

<inputtype="text" id="startTime" onFocus="WdatePicker({dateFmt:'yyyy-MM-dd',alwaysUseStartDate:true,onpicked:function(){onemonthtypeChange(this,'startTime','endTime');search();}})" class="j_toTimeMM" readonly="readonly" />

檢索結束時間:
<inputtype="text" id="endTime" onFocus="WdatePicker({dateFmt:'yyyy-MM-dd',alwaysUseStartDate:true,onpicked:function(){onemonthtypeChange(this,'startTime','endTime');search();}})" class="j_toTimeMM" readonly="readonly" /><script>
function onemonthtypeChange(obj,id1,id2){
  var start = $("#"+id1).val();
  var end = $("#"+id2).val();
  if(start != null && start != "" && end !=null && end != ""){
    var startNum,endNum;
    if(start.length > 5){
      startNum = parseInt(start.replace(/-/g,'').replace(' ','').replace(/:/g,''),10);
      endNum = parseInt(end.replace(/-/g,'').replace(' ','').replace(/:/g,''),10);
    }else{
      staetNum = parseInt(start.replace(/:/g,''),10);
      endNum = parseInt(end.replace(/:/g,''),10);
    }
    if(startNum > endNum){
      $(obj).val();
      alert("開始時間不能大於結束時間");
      return false;
    }
  }
  return true;
}
</script>
親測完美符合本身的需求
 

原文出處:https://www.cnblogs.com/bxcsx/p/10919051.htmlhtml

相關文章
相關標籤/搜索