以下代码适用于FF和IE8。现在(常规Win更新)IE一旦尝试应用ev_starttime
和ev_endtime
的任一或两个规则集的任何部分,就会冻结。 IE CPU使用率下降到50%,但内存使用率不受影响。任一浏览器都没有错误消息(使用Firebug for FF和IE Developer Tools for IE)。从CPU使用率的变化来看,我认为IE卡在循环中,但它不是其他任何人都能看到的循环。想法?
$("form[name='event_form']").validate({
debug: true,
rules: {
title: {required:true, minlength:5},
description: {required:true, minlength:5},
event_type_id: "required",
ev_start: { dateCan: true, required: true},
ev_end:{ dateCan: true,
minDate: "input[name='ev_start']"
},
ev_starttime:{
required:
function(element){
return $("input[name='allday']:unchecked");
},
time: true,
maxTime: {
depends: function(element) {
return $("input[name='ev_endtime']:filled")
&& $("input[name='ev_start']").valid()
&& $("input[name='ev_end']").valid()
&& $("input[name='ev_start']").val()==$("input[name='ev_end']").val();
},
param: "input[name='ev_endtime']"
}
},
ev_endtime:{
required:
function(element){
return $("input[name='allday']:unchecked")
},
time: true,
minTime: {
depends: function(element) {
return $("input[name='ev_start']").valid()
&& $("input[name='ev_end']").valid()
&& $("input[name='ev_starttime']").valid()
&& $("input[name='ev_start']").val()==$("input[name='ev_end']").val();
},
param: "input[name='ev_starttime']"
}
}
}
});
minTime和maxTime规则如下所示:
jQuery.validator.addMethod("minTime", function(value, element, param) {
try {
var aftertime=value.split(':');//hours and minutes
if($(param).val()=='') throw($param.name + ' empty');
var beforetime=$(param).val().split(':');
var at=new Date(0,0,0,aftertime[0],aftertime[1]*1);
var bt=new Date(0,0,0,beforetime[0],beforetime[1]*1);
return this.optional(element) || at > bt;
} catch(err){
return false;
}
}, function(param){
return "Time must occur after " + $(param).val();
}
);
jQuery.validator.addMethod("maxTime", function(value, element, param) {
try {
var beforetime = value.split(':');//hours and minutes
if($(param).val()=='') throw($param.name + ' empty');
var aftertime =$(param).val().split(':');
var at=new Date(0,0,0,aftertime[0],aftertime[1]*1);
var bt=new Date(0,0,0,beforetime[0],beforetime[1]*1);
return this.optional(element) || at > bt;
} catch(err){
return false;
}
}, function(param){
return "Time must occur before " + $(param).val();
}
);