此代码运行良好,但我想对其进行更改,以便它使用下拉菜单选项而不是复选框。例如,“更多?”的下拉菜单选项将是"is"或“否”。如果在菜单中选择了"is",那么我希望隐藏的 div 像选中当前代码中的复选框时一样显示。
JavaScript:
<script language="JavaScript">
function showhidefield()
{
if (document.frm.chkbox.checked)
{
document.getElementById("hideablearea").style.display = "block";
}
else
{
document.getElementById("hideablearea").style.display = "none";
}
}
</script>
这是 HTML:
<form name='frm' action='nextpage.asp'>
<input type="checkbox" name="chkbox" onclick="showhidefield()">
Check/uncheck here to show/hide the other form fields
<br>
<div id='hideablearea' style='visibility:hidden;'>
<input type='text'><br>
<input type='submit'>
</div>
This is a text line below the hideable form fields.<br>
</form>
谢谢。
最佳答案
将您的复选框替换为
<select name="more" onchange="showhidefield()">
<option value="yes">Yes</option>
<option value="yes">Yes</option>
</select>
并替换
if (document.frm.chkbox.checked)
在你的 showhidefield()
函数中
if (document.frm.more.value == 'yes')
关于javascript - 我如何更改此代码以显示带有下拉菜单而不是复选框的隐藏表单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8642058/