简体   繁体   English

IE8中的javascript match()错误

[英]javascript match() error in IE8

I am having problems figuring out why IE8 doesn't like this: 我在弄清楚为什么IE8不喜欢这样的问题:

//get all checked values from the checkboxes with the option_checkbox class
var values = $j('input:checkbox:checked.option_checkbox').map(function () { return this.value; }).get();
if (values.length>0){
  for (x in values){
    if(values[x].match("v")){ // <--this line causes a javascript error in IE8
      //do something here
    }
  }
}

I get this error: "Object does not support this property or method" 我收到此错误:“对象不支持此属性或方法”

I am thinking I should do some other sort of validation to verify type as perhaps map() and get() are not returning what I expect (a string with the value of that particular checkbox). 我想我应该做一些其他形式的验证来验证类型,因为map()和get()不会返回我期望的值(具有该特定复选框值的字符串)。

Any advice? 有什么建议吗?

试试这个代替:

values[x].match(/v/);

使用indexOf ,它的速度可以忽略不计

if(values[x].indexOf("v") > -1) { /* ... */ }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM