【发布时间】:2010-09-13 02:26:40
【问题描述】:
此函数在表单提交期间执行,在 Firefox 和 Chrome 中运行良好,但在 IE 中不行。我怀疑它是 indexOf,但我似乎找不到让它工作的方法。
function checkSuburbMatch(e) {
var theSuburb = document.getElementById('suburb').value;
var thePostcode = document.getElementById('postcode').value;
var arrayNeedle = theSuburb + " (" + thePostcode + ")";
if(suburbs.indexOf(arrayNeedle) != -1) {
alert("Suburb and Postcode match!");
return false;
} else {
alert("Suburb and Postcode do not match!");
return false;
}
}
【问题讨论】:
-
变量“郊区”包含什么?
-
这是一个字符串数组,沿着“suburbName (postCode)”的行进行
-
对于这个问题的彻底解释以及解决方法不仅是 indexOf 而是 IE 中其他缺失的数组函数,请查看 StackOverflow 问题stackoverflow.com/questions/2790001/…
-
FWIW 我有一个可以与 IE11 一起使用的开发环境,但是当我升级到我的测试环境时它停止工作了?!?!所以就像 IE 在某个地方有一个半生不熟的实现
标签: javascript internet-explorer indexof