我有很多复选框按钮,而不仅仅是两个。如果我可以接收,这些元素将循环分配相同的属性。但是这些项目存在于html标签的深处,我想通过使用jquery函数来接收它们。
我的html代码:
<div class="receiveCheckBox">
<div class="w3-col s12 m12 l12 w3-margin-top"><label>Card Number:</label>
</div>
<div class="w3-col s12 m12 l12 ">
<div class="w3-col s10 m10 l10"><input type="text" name="j_idt187" value="492095VAOSX10111" class="w3-input w3-border w3-round-large w3-disabled" disabled="disabled">
</div>
<div class="w3-col s2 m2 l2 w3-padding-left"><input id="cardNumberCheckBox" type="checkbox" name="cardNumberCheckBox" class="w3-check">
</div>
</div>
<div class="w3-col s12 m12 l12 w3-margin-top"><label>Phone Number:</label>
</div>
<div class="w3-col w3-full ">
<div class="w3-col s10 m10 l10"><input type="text" name="j_idt194" value="28828192287/T" class="w3-input w3-border w3-round-large w3-disabled" disabled="disabled">
</div>
<div class="w3-col s2 m2 l2 w3-padding-left"><input id="phoneCheckBox" type="checkbox" name="phoneCheckBox" class="w3-check">
</div>
</div>
<div class="w3-col w3-full w3-margin-top"><label>Email:</label>
</div>
<div class="w3-col w3-full ">
<div class="w3-col s10 m10 l10"><input type="text" name="j_idt201" value="LING_LUK620@HOTMAIL.COM" class="w3-input w3-border w3-round-large w3-disabled" disabled="disabled">
</div>
<div class="w3-col s2 m2 l2 w3-padding-left"><input id="emailCheckBox" type="checkbox" name="emailCheckBox" class="w3-check">
</div>
</div>
</div>
我的jquery函数:
$('.receiveCheckBox :checked').each(function() {
$(this).attr("disabled", true);
....
....
});
div标签类名称:“ receiveCheckBox”
但是此函数不会将复选框数组返回给我,所以我不会收到它们。
答案 0 :(得分:0)
我将使用此jquery函数处理此问题
$('.receiveCheckBox input[type="checkbox"]').each(function() {
$(this).attr("disabled", true); })
例如我的代码块在此代码块之前
function clearSelectionValueSet(){
$('#cardNumberCheckBox').removeAttr('checked').attr("unchecked", "");
$('#phoneCheckBox').removeAttr('checked').attr("unchecked", "");
$('#emailCheckBox').removeAttr('checked').attr("unchecked", "");
$('#carHolderFFPNumberCheckBox').removeAttr('checked').attr("unchecked", "");
$('#cardNumberCheckBox').attr("disabled", true);
$('#phoneCheckBox').attr("disabled", true);
$('#emailCheckBox').attr("disabled", true);
$('#carHolderFFPNumberCheckBox').attr("disabled", true);
}
由于
function clearSelectionValueSet() {
$('.receiveValueSetCheckBox input[type="checkbox"]').each(function() {
$(this).removeAttr('checked').attr("unchecked", "");
$(this).attr("disabled", true);
})
}
这是相同的,但对数组有用