IE7 不支持 indexOf javascript 是真的吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5937609/
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
Is it true that IE7 doesnt support indexOf javascript?
提问by matskn
Possible Duplicate:
.indexOf function on an array not working in IE7/8 using JavaScript
Im developing for IE7 and have some troubles with the javascript function indexOf.
我正在为 IE7 开发,并且在使用 javascript 函数 indexOf 时遇到了一些麻烦。
After browsing some sites I read that IE7 doesnt support indexOf. Is this correct, and if so, whats the easiest way to check if a string contains a given string?
浏览一些网站后,我读到 IE7 不支持 indexOf。这是正确的,如果是,检查字符串是否包含给定字符串的最简单方法是什么?
var test = window.location.toString();
test = test.toLowerCase();
var idString = "28A3CASDGAGHTSDASF34134";
idString = idString.toLowerCase();
if(test.indexOf(idString) > 0){
alert('worked');
}
Edit: Most likely some coding error by myself
编辑:很可能是我自己的一些编码错误
回答by Rudi Visser
As far as I'm aware, Array.indexOf
isn't supported, however String.indexOf
, as per your example above, is.
据我所知,Array.indexOf
不支持,但是String.indexOf
,根据您上面的示例,是。
The best way to work things like this out are to just try them in the browser you're querying. This is much more reliable than asking someone else, people have different browser configurations etc.
解决此类问题的最佳方法是在您查询的浏览器中尝试它们。这比询问其他人可靠得多,人们有不同的浏览器配置等。
Update: See this MSDN documentation pageabout indexOf, it's been supported since IE6.
更新:请参阅有关 indexOf 的MSDN 文档页面,自 IE6 起就支持它。