好吧,那確實是一個很奇怪的問題,但它真的發生在我身上,我寫了一個JS,它在IE上工作,但它沒有火狐或鉻。在IE上工作的JS,不能在Chrome和FF上工作
我希望如果有人能與爲什麼發生這種情況賜教...
我的HTML代碼是下一個
<h4>What kind of animals do you like the most?</h4>
<select id="animalName" name="animalName">
<option selected="selected" disabled="disabled">Which animal is it?</option>
<option value="Cat">Cat</option>
<option value="Dog">Dog</option>
<option value="Lion">Lion</option>
<option value="Other">Other</option>
</select>
<div id="otherAnimalNameDiv">
<h4>As you picked the other, would you like to write it down to let us know?</h4>
<input type="text" name="otherAnimalName" size="40" id="otherAnimalName" />
</div>
而我的JS代碼是下一個:
var animalName = document.getElementById("animalName");
var animalOtherName = document.getElementById("otherAnimalNameDiv");
function animalSelect(){
animalName.onchange = function(){
if (animalName.options.value == "Other"){
animalOtherName.style.display = "block";
}
};
animalOtherName.style.display = "none";
}
window.onload = function() {
firstNameFunc();
familyNameFunc();
emailAddressFunc();
passwordFunc();
rewritePasswordFunc();
colorPickerFunc();
animalSelect();
}
爲什麼它會在IE上運行,而不會在Chrome或FF上運行?...
當您選擇「其他」選項時從選擇標籤它應該設置div顯示屏蔽,這發生在IE上,但不是FF或鉻。
你有沒有真的_invoke_' animalSelect'? – Zeta 2013-04-11 18:44:35
你沒有真正解釋過什麼對你的代碼不起作用。另外,一些JS代碼可能在一個瀏覽器中工作,但不是另一個,這並不奇怪。它被稱爲[跨瀏覽器兼容性](https://www.google.com/search?q=cross+browser+compatibility)。 – Travesty3 2013-04-11 18:46:56