简体   繁体   English

如何在单击时链接一个单选按钮以显示不同的下拉菜单,同时将当前选择的单选按钮隐藏在同一位置?

[英]How can I link one radio button on click to display a different drop down while hiding the one currently selected in the same location?

As explained above, I would like my second radio button (single) to be able to display the second form (commented below) when it is clicked, and then be able to hide the current form (group).如上所述,我希望我的第二个单选按钮(单个)能够在单击时显示第二个表单(如下注释),然后能够隐藏当前表单(组)。 Thank you to anyone willing to help ahead of time.感谢任何愿意提前提供帮助的人。

<!--Using HTML, CSS, and JavaScript is preferred-->
    <div class="box3-flex">
      <h4 class="name">Name:</h4>

      <form id="form1" class="form">
        <select name="sendingfrom" class="click-op">
          <option value="group-select">arm</option>
          <option value="group-select">all</option>
        </select>
      </form>
    
      <!--This is the form I would like to link to the radio button "single"-->
      <form id="form2" class="form">
        <select name="sendingfrom" class="click-op">
          <option value="group-select">position</option>
          <option value="group-select">velocity</option>
        </select>
      </form>
    
      <input type="radio" id="group" name="group-or-single" value="group">
        <label for="group">Group</label>
    
      <input type="radio" id="single" name="group-or-single" value="single">
        <label for="single">Single</label>
    </div>
    
    <style>
      div.box3-flex {
        display: flex;
        margin-top: 30px;
      }
    
      h4.name {
        margin: 3px 0px;
      }
    
      select.click-op {
        padding: 5px 160px 5px 5px;
        margin-left: 5px;
      }
    </style>

If you're just looking to toggle the visibility of the dropdowns when selected then this should be a good place to get you started.如果您只是想在选择时切换下拉菜单的可见性,那么这应该是您入门的好地方。 Just toggle the visibility style attribute when the user clicks a radio button.只需在用户单击单选按钮时切换可见性样式属性。

 function single() { var groupForm = document.getElementById('form1'); var singleForm = document.getElementById('form2'); groupForm.style.visibility = 'hidden'; singleForm.style.visibility = 'visible'; } function group() { var groupForm = document.getElementById('form1'); var singleForm = document.getElementById('form2'); singleForm.style.visibility = 'hidden'; groupForm.style.visibility = 'visible'; }
 div.box3-flex { display: flex; margin-top: 30px; } h4.name { margin: 3px 0px; } select.click-op { padding: 5px 160px 5px 5px; margin-left: 5px; }
 <div class="box3-flex"> <h4 class="name">Name:</h4> <form id="form1" class="form"> <select name="sendingfrom" class="click-op"> <option value="group-select">arm</option> <option value="group-select">all</option> </select> </form> <form id="form2" class="form"> <select name="sendingfrom" class="click-op"> <option value="group-select">position</option> <option value="group-select">velocity</option> </select> </form> <input type="radio" id="group" name="group-or-single" value="group" onclick="group()"> <label for="group">Group</label> <input type="radio" id="single" name="group-or-single" value="single" onclick="single()"> <label for="single">Single</label> </div>

 const radio = document.getEelmentById('single'); const form = document.getElementById('form2'); radio.addEventListener('click', () => { form.style.display = 'block'; })

By default make the form2 display:none默认情况下,使 form2 显示:无

 #form2{ display: none; }

After the user click radio(with id of 'single') then the form2 wil be displayed.用户单击单选(ID 为“single”)后,将显示 form2。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何根据选定的单选按钮值传递单选按钮值? - How can i pass radio button values based on the selected one? 一个按钮如何根据选择的单选按钮显示不同的结果 - How can a button display different results depending on radio button selected 我如何在网页上单击与我当前使用 javascript (Tampermonkey) 打开的按钮不同的按钮 - How do i click a button on a webpage different from the one i currently have open using javascript (Tampermonkey) 如何显示所选下拉菜单中的类别之一 - How do I display one of the categories from selected drop-down 隐藏列共享点的下拉值无法正常工作,但在不同会话中一一选择值时它可以工作 - drop down value for hiding the columns share point is not working properly , but it works when value is selected one by one in different sessions 如果选择了另一个名称不同的按钮,如何取消选择单选按钮 - How to deselect a radio button if another one with a different name is selected 如果已选择一个单选按钮,如何禁用一组单选按钮,如果未选择一个单选按钮并单击下一个按钮,如何显示警报 - How to disable a group of radio buttons if one has been selected and display an alert if one is not selected and the next button is clicked 单击链接以显示下拉列表 - Click on link to display a drop down 当在一个下拉列表中选择一个选项时,如何使用javascript在另一个下拉列表中显示其相关值 - when one option selected in one drop down list then how to display its related value in another drop down list using javascript 如何根据选择的单选按钮更改下拉列表的值? - How to change value of a drop down list depend on selected radio button?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM