我想隐藏基于另一个电台组选择的div。只有在第一组单选按钮的值等于3时,才会显示底部集。我只是无法让它工作。我在这里做错了什么?隐藏与Jquery不工作的div
HTML:
<label>
<input name="Weekend" type="radio" id="Weekend_0" class="Weekend" value="1" checked="checked" />
Saturday</label>
<br />
<label>
<input type="radio" name="Weekend" value="2" class="Weekend" id="Weekend_1" />
Sunday</label>
<br />
<label>
<input name="Weekend" type="radio" id="Weekend_2" class="Weekend" value="3" />
No</label>
<br />
<div class="wrapper">
<label>
<input name="AMPM" type="radio" id="AMPM_0" value="1" checked="checked" />
AM</label>
<br />
<label>
<input type="radio" name="AMPM" value="2" id="AMPM_1" />
PM</label>
<br />
</div>
JS:
$('input:radio[name="Weekend"]').click(function() {
var $this = $(this);
if ($this.val() == 3) {
$this.nextAll('.wrapper').show();
} else {
$this.nextAll('.wrapper').hide();
}
});
谢谢!
我不相信输入属于标签 – andrew
@andrew它应该没问题 - https://developer.mozilla.org/en-US/docs/Web/HTML/Element/label#Examples和http: //www.w3.org/TR/html401/interact/forms.html#h-17.9.1和http://www.w3.org/TR/html5/forms.html#the-label-element –