如何更改此代码以显示带有下拉菜单而不是复选框的隐藏表单?

发布于 2024-12-23 03:18:26 字数 929 浏览 0 评论 0原文

这段代码运行得很好,但我想更改它,以便它使用下拉菜单选项而不是复选框。例如,“更多?”的下拉菜单选项会是“是”或“否”。如果在菜单中选择“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦与时光遇 2024-12-30 03:18:26

将您的复选框替换为

<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')

Replace your checkbox with

<select name="more" onchange="showhidefield()">
  <option value="yes">Yes</option>
  <option value="yes">Yes</option>
</select>

And replace the

if (document.frm.chkbox.checked) 

in your showhidefield() function with

if (document.frm.more.value == 'yes')
多情出卖 2024-12-30 03:18:26
<form name='frm' action='nextpage.asp'>
  <select name="chkbox" onChange="showhidefield(this)">
     <option value="0" selected="true">-Select-</option>
    <option value="1">Yes</option>
    <option value="2">No</option>
  </select>
  Check/uncheck here to show/hide the other form fields
  <br>
  <div id='hideablearea' style='display:none;'>
    <input type='text'><br>
    <input type='submit'>
  </div>
  This is a text line below the hideable form fields.<br>
</form>

JavaScript 代码是:

<script language="JavaScript">
  function showhidefield(that)
  {
    if (that.value == 1)
    {
      document.getElementById("hideablearea").style.display = "block";
    }
    else
    {
      document.getElementById("hideablearea").style.display = "none";
    }
  }
</script>
<form name='frm' action='nextpage.asp'>
  <select name="chkbox" onChange="showhidefield(this)">
     <option value="0" selected="true">-Select-</option>
    <option value="1">Yes</option>
    <option value="2">No</option>
  </select>
  Check/uncheck here to show/hide the other form fields
  <br>
  <div id='hideablearea' style='display:none;'>
    <input type='text'><br>
    <input type='submit'>
  </div>
  This is a text line below the hideable form fields.<br>
</form>

And javascript code is:

<script language="JavaScript">
  function showhidefield(that)
  {
    if (that.value == 1)
    {
      document.getElementById("hideablearea").style.display = "block";
    }
    else
    {
      document.getElementById("hideablearea").style.display = "none";
    }
  }
</script>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文