重写jQuery验证Internet Explorer的代码段

时间:2011-02-17 15:44:45

标签: jquery internet-explorer jquery-validate

以下代码适用于除Internet Explorer之外的所有浏览器。

任何人都可以告诉我在Internet Explorer中要改变它的内容吗?

非常感谢

<script type="text/javascript">

$(function() {
    $.getScript( "http://jquery.bassistance.de/validate/jquery.validate.js", dependsOnValidate );
});

function dependsOnValidate() {

  $.validator.setDefaults({ submitHandler: function() { alert( "Valid" ); } });

  $("#form_login").validate({
    rules: {
        EMAIL: {
            required: true,
          email: true
        },
        PASS: {
            required: true,
          minlength: 4
        },
        },
    messages: {
        EMAIL: " need a valid email",   
        PASS: {
        required: " required",
        minlength: " too short"
        }
        }
  });   

} 
</script>

1 个答案:

答案 0 :(得分:2)

PASS: {
                required: true,
              minlength: 4
            },

删除此代码块中的最后一个逗号,IE不喜欢JSON中的额外逗号

稍后编辑:完成正确的代码:




$(function() {
    $.getScript( "http://jquery.bassistance.de/validate/jquery.validate.js", dependsOnValidate );
});

function dependsOnValidate() {

  $.validator.setDefaults({ submitHandler: function() { alert( "Valid" ); } });

  $("#form_login").validate({
    rules: {
        EMAIL: {
            required: true,
          email: true
        },
        PASS: {
            required: true,
          minlength: 4
        }
        },
    messages: {
        EMAIL: " need a valid email",   
        PASS: {
        required: " required",
        minlength: " too short"
        }
        }
  });   

}