1

我在 IE9 中遇到上述错误,但我不明白为什么会这样。我试图找到解决此问题的方法,但处于死胡同。有人可以指出我哪里出错了。起初我以为这可能是最后一个逗号,但事实并非如此。谢谢

jQuery代码

$.validator.setDefaults ({

        errorClass: 'form_error',
        errorElement: 'div'
    });

    $("#BA_boxform").validate({
        rules: {
            BA_customer: {
                required: true
            },
            customerdept: {
                required: true
            },
            customeraddress: {
                required: true
            },
            BA_service: {
                required: true
            },
            BA_box: {
                required: true
            },
            BA_destdate: {
                required: true
            },
            BA_authorised: {
                required: true
            }
        },
        messages: {
            BA_customer: {
                required: '<br />* required: You must select a customer'
            },
            customerdept: {
                required: "<br />* required: You must select a department"
            },
            customeraddress: {
                required: "<br />* required: You must select a customer address"
            },
            BA_service: {
                required: "<br />* required: You must select a service level"
            },
            BA_box: {
                required: "<br />* required: You must enter a box number for intake"
            },
            BA_destdate: {
                required: "<br />* required: You must enter a destruction date"
            },
            BA_authorised: {
                required: "<br />* required"
            } **<--- error is reported here**
        },
    });
4

3 回答 3

3

问题在于结尾的逗号:

        } **<--- error is reported here**
    }, <--- problem is here
于 2013-07-02T12:46:42.580 回答
1
messages: {
            BA_customer: {
                required: '<br />* required: You must select a customer'
            },
            customerdept: {
                required: "<br />* required: You must select a department"
            },
            customeraddress: {
                required: "<br />* required: You must select a customer address"
            },
            BA_service: {
                required: "<br />* required: You must select a service level"
            },
            BA_box: {
                required: "<br />* required: You must enter a box number for intake"
            },
            BA_destdate: {
                required: "<br />* required: You must enter a destruction date"
            },
            BA_authorised: {
                required: "<br />* required"
            } **<--- error is reported here**
        }, // <- Problem is here

删除最后一个逗号。它应该可以正常工作。

于 2013-07-02T12:47:48.823 回答
1

删除属性中的逗号messages。数组中的最后一个元素不应包含逗号,否则 IE 会抛出错误。

$("#BA_boxform").validate({
   rules: {
      // rules
   },
   messages : {
      // messages.
   }, // REMOVE THE TRAILING COMMA
});

应该改为

$("#BA_boxform").validate({
   rules: {
      // rules
   },
   messages : {
      // messages.
   }
});
于 2013-07-02T12:46:24.360 回答