简体   繁体   English

如何基于先前选择的单选按钮动态隐藏单选按钮?

[英]How to dynamically hide the radio buttons based on the previously selected radio buttons?

So, there are some sections of radio buttons in the following way 因此,单选按钮的某些部分采用以下方式

SECTION 1 第1节

Radio1 Radio2 Radio3 收音机1收音机2收音机3

SECTION2 SECTION2

Radio4 Radio5 Radio4 Radio5

SECTION3 SECTION3

Radio6 Radio7 Radio8 Radio9 收音机6收音机7收音机8收音机9

Let's say Radio2 is selected. 假设选择了Radio2。 Now I'll have to hide the whole SECTION3 radio buttons instantly. 现在,我必须立即隐藏整个SECTION3单选按钮。 How should I implement this? 我应该如何实施呢? The code that currently exists is: 当前存在的代码是:

.form-group(ng-repeat="attribute in object.attributes" style="position: relative; float: left;")
    label.control-label {{attribute}}
    ul.option-list
          li(ng-repeat="x in object[attribute] | orderBy: 'x'")
              .radio
                  label
                      input.btn(type="radio", ng-model="product[attribute]", ng-value="x", ng-selected)
                      | {{x}}

Here the names SECTION1 , SECTION2 etc come from attribute, while the names of the radio buttons come from the x in object[attribute] 这里的名称SECTION1SECTION2等来自属性,而单选按钮的名称则来自对象中的x [attribute]

Any help would be much appreciated. 任何帮助将非常感激。 Thanks in advance. 提前致谢。

UPDATE: 更新:

Here I am trying to hide the other section of radio buttons only if a particular radio button from one section is selected. 在这里,我仅在选择一个区域中的特定单选按钮时才尝试隐藏单选按钮的另一部分。 If Radio button 2 of section 1 is selected, then only section 3 must be hidden. 如果选择了第1部分的单选按钮2,则仅第3部分必须隐藏。 If Radio button 3 of section 2 is selected, then hide section 4 also. 如果选择了第2部分的单选按钮3,则也隐藏第4部分。

Lets say you have an HTML like this 假设您有这样的HTML

<div id='firstSection'>
    <input type='radio' name='sectionOne' value='Radio 1' /> 
    <input type='radio' name='sectionOne' value='Radio 1' />
    <input type='radio' name='sectionOne' value='Radio 1' />
</div>

<hr/>

<div id='secondSection'>
    <input type='radio' name='sectionOne' value='Radio A' /> 
    <input type='radio' name='sectionOne' value='Radio B' />
    <input type='radio' name='sectionOne' value='Radio C' />
</div>

Then you'll need a function like below in your javascript. 然后,您需要在JavaScript中使用以下功能。

    function HideSection(){

    $('input:radio').change(function(e){
        // get the id of element to hide
        var selectedSectionId = $(this).parent().attr('id')
        var sectionToHide;
        if(selectedSectionId.indexOf('first') != -1)
         sectionToHide = selectedSectionId.replace('first','second');
        else
         sectionToHide = selectedSectionId.replace('second','first');
        // hide the element
        $('#' + sectionToHide).hide();
    });    
}

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM