此函数在表单onSubmit期间执行,并且在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;
}
}
Run Code Online (Sandbox Code Playgroud)