Chức năng này thực hiện trong các biểu mẫu onSubmit và hoạt động tốt trong Firefox và Chrome, nhưng không hoạt động trong IE. Tôi nghi ngờ đó là indexOf, nhưng tôi dường như không thể tìm cách để làm cho nó hoạt động.Tại sao indexOf không hoạt động trong Internet Explorer?
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;
}
}
Biến "ngoại ô" có chứa gì? – Tim
Đó là một chuỗi các chuỗi đi dọc theo dòng "suburbName (postCode)" – David
có thể trùng lặp của [Tại sao không indexOf làm việc trên một mảng IE8?] (Http://stackoverflow.com/questions/3629183/why-doesnt -indexof-work-on-an-array-ie8). Xem thêm: [Làm thế nào để sửa lỗi Array indexOf() trong JavaScript cho trình duyệt IE] (http://stackoverflow.com/questions/1744310/), [Array indexOf thực hiện cho Internet Explorer] (http://stackoverflow.com/questions/2868696) – CMS