单选按钮组显示所选值 jQuery 上的项目
radio group show items on selected value jQuery
有一个无线电组在更改时想要显示 arrt 包含所选无线电值的标签,这是我的代码
<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>
这是我的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();
}
});
});
试试这个:在更改单选按钮时,使用.filter()
遍历所有priceswrapper
。检查 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();
});
});
演示
试试这个:-
$('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();
}
});
});
演示 :- http://jsfiddle.net/shrshcqn/
相关文章:
- 动态地改变“”的URL;添加新项目”;链接使用javascript/jquery
- 学生搜索项目jquery/javascript
- 无法在jquery中向上或向下移动列表中的多个项目
- 使用jQuery插入HTML页面的第一个项目缺少结束标记
- 使用JavaScript或jQuery检查单选按钮选择是否与数组中的项目匹配
- JQuery和Javascript没有'在我的项目中不起作用,但在网络上起作用
- jQuery:根据select选项中的每页项目进行分页
- 我在页面中使用的jQuery UI可排序项目;不起作用
- 如何使用jquery将所选项目从一个下拉组列表(optgroup)移动到另一个下拉列表(optgroup)
- jQuery无限循环,动画化许多项目
- 如何让li项目在这个jQuery列表中滑动和/或淡出视图
- 根据jQuery针对特定项目
- 在此项目中使用jQuery或JavaScript中的选择器
- jquery ias插件不适用于我的网站,加载更多项目不起作用
- 为图像滑块jquery添加项目符号功能
- 第一个jquery项目-在函数中使用处理程序来模块化它们
- 第一个JQuery项目..有点卡住了
- 如何检查PHP和jquery项目中代码重定向的位置
- 将我的Jquery项目更改为纯javascript
- JQuery项目.视图中的ID