下面是我的jQuery代码,我如何更改它,以便我不重复相同的代码,因为变量正在改变?它用于使用隐藏/显示的多个单选按钮。jquery多个单选按钮
我的单选按钮有一个类"someclass"
:
<input class="someclass" id="different1" type="radio" value="Yes" /> <input class="someclass" id="different1" type="radio" value="No" />
<input class="someclass" id="different2" type="radio" value="Yes" /><input class="someclass" id="different2" type="radio" value="No" />
<input class="someclass" id="different3" type="radio" value="Yes" /><input class="someclass" id="different3" type="radio" value="No" />
我的div都有相同的类:
<div class="divclass" style="display:none" id="notthesame1"></div>
<div class="divclass" style="display:none" id="notthesame2"></div>
<div class="divclass" style="display:none" id="notthesame3"></div>
$("input[name='different1']").click(function() {
$('#notthesame1').css('display', ($(this).val() === 'Yes') ? 'block' : 'none');
});
$("input[name='different2']").click(function() {
$('#notthesame2').css('display', ($(this).val() === 'Yes') ? 'block' : 'none');
});
$("input[name='different2']").click(function() {
$('#notthesame2').css('display', ($(this).val() === 'Yes') ? 'block' : 'none');
});
'name'属性应该是相同的才能组选项。 –