如何更改此代码以显示带有下拉菜单而不是复选框的隐藏表单?
这段代码运行得很好,但我想更改它,以便它使用下拉菜单选项而不是复选框。例如,“更多?”的下拉菜单选项会是“是”或“否”。如果在菜单中选择“yes”,那么我希望隐藏的 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>
谢谢。
This code is working great, but I'd like to change it so it uses a drop-down menu choice instead of a checkbox. For example, the Dropdown menu choices for "More?" would be "yes" or "no". If "yes" is selected in the menu, I then want the hidden div to show just like it does when one checks the checkbox in the current code.
The 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>
And this is the 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>
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将您的复选框替换为
替换为
将
showhidefield()
函数中的Replace your checkbox with
And replace the
in your
showhidefield()
function withJavaScript 代码是:
And javascript code is: