我有一个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