为什么我在Internet Explorer 7.0和8.0中出错?

时间:2012-10-18 17:21:56

标签: jquery internet-explorer-8 internet-explorer-7 jquery-validate jquery-1.7

我对我的字段使用自定义验证

<div class="control-group">
  <label class="control-label" for="region">Region*</label>
  <div class="controls">
    <input type="text" class="input-xlarge" id="region" name="region" minlength="1" maxlength="50" autocomplete="off">
  </div>
</div>

var regionsList = ["value1", "value2", ..., "value 80"];

$.validator.addMethod("validRegion", function (value, element, param) {
  return this.optional(element) || (param.indexOf(value) != -1); // ERROR IS HERE
}, "Please start to type and choose correct value");

$("#myform").validate({
  rules: {
    "region": {
      required: true,
      validRegion: regionsList
    },
 ...

这一行可能出现什么问题(请查看评论错误的行在这里)? 错误是Object doesn't support this property or method

1 个答案:

答案 0 :(得分:4)

仅在IE 9+上支持

Array.indexOf。由于您已经在使用jQuery,因此可以使用$.inArray(如果支持的话,它将使用Array.indexOf。)

$.validator.addMethod("validRegion", function (value, element, param) {
  return this.optional(element) || ($.inArray(value, param) != -1);
}, "Please start to type and choose correct value");