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

标签 javascript forms hide

此代码运行良好,但我想对其进行更改,以便它使用下拉菜单选项而不是复选框。例如,“更多?”的下拉菜单选项将是"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/

相关文章:

javascript - 在音频结束后执行操作

javascript - 如何使用html代码制作响应式框?

javascript - 过滤数据时更改按钮的颜色

php - 如何隐藏php代码和mysql表模式

jquery - 在不同函数中对同一元素使用 hide()

javascript - 带有嵌套 ionic 导航 View 的 ionic 导航 View 不起作用

javascript - 提交时未显示输入字段

javascript - 在表单提交时将一个 html 文档拆分为多个文档

sql - 查询过滤,在灵活性和易于执行之间找到平衡

magento - 如何在 magento 中删除或隐藏特定页面的面包屑