我有一個javascript switch case語句來重定向頁面或顯示/隱藏文本框取決於用戶從下拉框中選擇的值。它在Firefox中正常工作,但不是IE。該錯誤消息是如下: SCRIPT5007:無法獲得屬性「值」的值:對象爲空或未定義 _index.htm 67行字符7Javascript下拉選定的值在IE中不起作用
開關(document.form.description.options [描述.selectedIndex] .value) - IE瀏覽器在form.desciprition上遇到困難。
<script language="javascript">
function fundsource()
{
var val;
for (i=0; i< document.form.description.length; i++)
{
switch (document.form.description.options[description.selectedIndex].value)
{
case "Select":
document.form.scholarship.style.visibility='hidden';
document.form.description_other.style.visibility='hidden';
break;
case "Wall of Friends":
location.href= some url
break;
case "Scholarship":
document.form.scholarship.style.visibility='visible';
break;
case "Other":
document.form.description_other.style.visibility='visible';
document.getElementById("descriptionspan").style.visibility="visible";
break;
}
}
}
</script>
HTML如下代碼:
<tr>
<td align="right">Description of the Fund for Your Donation <br /></td>
<td>
<select name="description" id="description" onchange="fundsource()">
<option>Select</option>
<option>Scholarship</option>
<option>Rainbow of Life</option>
<option>Wall of Friends</option>
<option>General</option>
<option>Other</option>
</select>
<select name="scholarship" id="scholarship" style="visibility:hidden;">
<option>Alumni Scholarship</option>
<option>Other</option>
</select>
</td>
</tr>
<tr>
<td align="right" valign="top"><div id="descriptionspan" alt="description" style="visibility:hidden;">Other, please specify:</div></td>
<td><input type="text" name="description_other" size="50" alt="Fund Other" style="visibility:hidden;" /></td>
</tr>
我改變了document.form.description.options [description.selectedIndex]。價值到document.form.description.options [description.selectedIndex]。文字,它仍然不起作用。請指教。 TIA。
既然你給了''
我不認爲這實際上適用於Firefox。如果你通過「selectedIndex」屬性檢查,那麼你根本不需要循環。 – Pointy
很酷。它像一個魅力。 – user788448