默认情况下,所有复选框均处于未选中状态。我无法在问题中使用单选按钮。
当复选框更改为 'checked'
时然后查看是否有任何兄弟复选框是 'checked'
,如果是那么.click()
家长<label>
复选框。
我必须.click()
<label>
因为连接的 API 正在监听标签上的单击,$('input').prop("checked", false);
似乎不起作用。
结构如下:
<div class="feature-filter">
<div id="filterHandle">Product Filter</div>
<label class="featureLabel">
<input class="featureCheck" type="checkbox">
Original Pouch
</label>
<label class="featureLabel">
<input class="featureCheck" type="checkbox">
Original Can
</label>
<label class="featureLabel">
<input class="featureCheck" type="checkbox">
Gold Pouch
</label>
<label class="featureLabel">
<input class="featureCheck" type="checkbox">
Gold Can
</label>
<label class="featureLabel">
<input class="featureCheck" type="checkbox">
Menthol Pouch
</label>
<label class="featureLabel">
<input class="featureCheck" type="checkbox">
Menthol Can
</label>
</div>
这是我尝试过的,但它是错误的。
$('.featureCheck').click(function(){
if $('.featureCheck').siblings().prop('checked',true){
this.find('label').click();
}
});
最佳答案
听起来你想要这样的东西:
$('.featureCheck').change(function() {
if (this.checked) {
$('.featureCheck').not(this).filter(':checked').closest('.featureLabel').click();
}
});
因此,如果您选中一个复选框,找到其他已选中的复选框,并在其父标签
上触发点击事件
关于javascript - 如果 checkbox 属性检查为 true,则单击 Label,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28219354/