Javascript IE:indexOf 导致“对象不支持此属性或方法”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10923434/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
IE: indexOf results in "object doesn't support this property or method"
提问by Fraser
I have the following if statement:
我有以下 if 语句:
if (buyArray.indexOf(dealWith,0) != -1){
Which is breaking in ie (ie 8 on XP) with "object doesn't support this property or method".
这是闯入即(即XP 上的8)与“对象不支持此属性或方法”。
Anyone have a work around for this?
任何人都可以解决这个问题?
回答by ZER0
yeah, IE<9 doesn't support indexOf
. You can implement a shim like the one showed here: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf
是的,IE<9 不支持indexOf
. 你可以实现一个像这里展示的垫片:https: //developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf
Or if you already using jQuery you can use inArray. Also underscorehas an implementation for it.
回答by Fraser
Simply changed to the use jQuery.inArray. Thanks to ZER0 for the heads up
简单地改为使用jQuery.inArray。感谢 ZER0 的提醒
if ($.inArray(dealWith, buyArray) != -1) {