我有一个 javascript switch case 语句来重定向页面或显示/隐藏文本框,这取决于用户从下拉框值中选择的内容。它在 Firefox 中运行良好,但在 IE 中运行良好。错误信息如下: SCRIPT5007: Unable to get value of the property 'value': object is null or undefined _index.htm, line 67 character 7
switch (document.form.description.options[description.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].value 更改为 document.form.description.options[description.selectedIndex].text,它仍然不起作用。请指教。TIA。