IE9预期的标识符,字符串或数字错误

时间:2013-07-02 12:41:56

标签: jquery internet-explorer

我在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**
        },
    });

3 个答案:

答案 0 :(得分:3)

问题在于尾随逗号:

        } **<--- error is reported here**
    }, <--- problem is here

答案 1 :(得分:1)

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

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

应改为

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

答案 2 :(得分: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

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