简体   繁体   English

单选组在选定值上显示项目jQuery

[英]radio group show items on selected value jQuery

have a radio group on change would like to show labels that arrt includes selected radio value, here is my code 有一个更改的广播组想显示标签,其中包括所选的广播值,这是我的代码

<label class="radio"><input name="tour_type" type="radio" value="reg" />Regular</label>
<label class="radio"><input type="radio" name="tour_type" value="div" />Diving</label>
<label class="radio"><input type="radio" name="tour_type" value="qud"  />Quad</label>
<label class="radio"><input type="radio" name="tour_type" value="prv" />Privat</label>

<label class=" priceswrapper" style="display:none;" tour_type="reg, div">Pax<input type="text" /></label>
<label class=" priceswrapper" style="display:none;" tour_type="reg, div">Kids<input type="text" /></label>
<label class=" priceswrapper" style="display:none;" tour_type="reg, div">Intro Dive<input type="text" /></label>
<label class=" priceswrapper" style="display:none;" tour_type="reg, div">Professional Dive<input type="text" /></label>
<label class=" priceswrapper" style="display:none;" tour_type="qud">Single quad<input type="text" /></label>
<label class=" priceswrapper" style="display:none;" tour_type="qud">Doubble quad<input type="text" /></label>
<label class=" priceswrapper" style="display:none;" tour_type="qud">Private quad<input type="text" /></label>
<label class=" priceswrapper" style="display:none;" tour_type="prv">Private<input type="text" /></label>

and this is my jQuery code 这是我的jQuery代码

$('input[name=tour_type]').change(function(){
        var tour_type= $(this).val();

        $('.priceswrapper', function(){
            var prices_attr = [$(this).attr('tour_type')];
            if ($.inArray(tour_type, window.prices_attr) !== -1){
                $(this).show();
                }


            });
        });

Try this : on change of radio button iterate through all priceswrapper using .filter() . 尝试以下操作:在单选按钮更改时,使用.filter()遍历所有priceswrapper Check the value of tour_type and if exist then make it visible using .show() 检查tour_type的值,如果存在,则使用.show()使其可见

$(function(){
  $('input[name=tour_type]').change(function(){
       var tour_type= $(this).val();
    $('.priceswrapper').hide();
    $('.priceswrapper').filter(function(){
       var tourType = $(this).attr('tour_type');
       return tourType.indexOf(tour_type)!=-1;
    }).show();
  });
});

DEMO 演示

Try this:- 尝试这个:-

$('input[name=tour_type]').change(function(){
    var tour_type= $(this).val();

    var divs = $('.priceswrapper')
    $.each(divs, function(index,item){

        if($(item).attr('tour_type').split(',').indexOf(tour_type)){
        $(item).show();
        }else{
         $(item).hide();
        }

        });
    });

Demo :- http://jsfiddle.net/shrshcqn/ 演示: -http : //jsfiddle.net/shrshcqn/

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

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