踩过无数坑,调试了很长时间,写出适合自己需求的方法
需求:没有查询按钮,要求选择日期后自动触发查询事件(只有日期选择完成后才触发),
解决方案:代码如下:
检索开始时间:
<input
type="text"
id="startTime" onFocus="WdatePicker({dateFmt:'yyyy-MM-dd',alwaysUseStartDate:true,onpicked:function(){onemonthtypeChange(this,'startTime','endTime');search();}})" class="j_toTimeMM" readonly="readonly" />
检索结束时间:
<input
type="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>
亲测完美符合自己的需求