jQuery验证在依赖字段上冻结IE8

时间:2010-04-29 19:20:03

标签: internet-explorer jquery-validate

以下代码适用于FF和IE8。现在(常规Win更新)IE一旦尝试应用ev_starttimeev_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();
    }
);

0 个答案:

没有答案