jquery - 为什么我在 Internet Explorer 7.0 和 8.0 中遇到错误?

标签 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
    },
 ...

这一行可能有什么问题(请查找带有注释 ERROR IS HERE 的行)? 错误是对象不支持此属性或方法

最佳答案

Array.indexOf仅 IE 9+ 支持。由于您已经在使用 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");

关于jquery - 为什么我在 Internet Explorer 7.0 和 8.0 中遇到错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12960255/

相关文章:

css - IE8 - 导航链接不工作

html - 负边距导致边框在IE7中消失

javascript - 避免之前的 javascript 代码绑定(bind)的重定向操作

javascript - 将 div 滚动到其他 div 旁边

javascript - 当其他功能运行时单击按钮触发

css - 在 IE7 或 IE8 中查看打印 CSS

javascript - IE8 上的 jQuery,错误 : Object doesn't support this property or method

javascript - Windows Media Center 中的 IE 7 是全功能的 IE 吗?

css - 与 IE7 兼容的水平导航中类似表格的行为

jquery - 使用 jquery 获取跨度内的文本