我有一个复选框“.invalidDropChk”,当我点击它时,我希望它的子复选框被点击。那部分工作正常。我也有一个“全部”复选框。如果检查页面“.invalidOffensive”中的其他复选框,我想检查它。但问题是它输入if和else部分到底并且我的复选框“All”被检查。这是代码:
$('.invalidDropChk').live('click',function(){
if($(this).is(':checked')){
$(this).next().find('input[type="checkbox"]').attr('checked',true);
$(this).attr('checked',true);
var rad1 = document.getElementById("invalidDropChk");
if(rad1 != null && rad1.attributes['checked'])
rad1.checked = true;
}
else
{
$(this).next().find('input[type="checkbox"]').attr('checked',false);
$(this).attr('checked',false);
var rad1 = document.getElementById("invalidDropChk");
if(rad1 != null && rad1.attributes['checked'])
rad1.checked = false;
}
if (($(this).is(':checked')) && ($('.invalidOffensive').is(':checked'))){
$('.check-all ').prop('checked',true);
}
else{
$('.check-all ').prop('checked',false);
}
});
jsp页面代码是:
<ul class="invalidDrop">
<c:choose>
<c:when test="${invalidDropForm.invalidStreetAddress==true && invalidDropForm.invalidSubName==true && invalidDropForm.derogatoryNames==true && invalidDropForm.businessNames==true && invalidDropForm.offensiveNames==true}">
<li><input type="checkbox" class="check-all" checked /> All</li>
</c:when>
<c:otherwise>
<li><input type="checkbox" class="check-all" /> All</li>
</c:otherwise>
</c:choose>
<li>
<c:choose>
<c:when test="${invalidDropForm.invalidStreetAddress==true && invalidDropForm.invalidSubName==true}">
<input type="checkbox" class="check-inside invalidDropChk" id="invalidDropChk" checked /> Invalid Name/Address
</c:when>
<c:otherwise>
<input type="checkbox" class="check-inside invalidDropChk" id="invalidDropChk" /> Invalid Name/Address
</c:otherwise>
</c:choose>
<ul class="inneritem">
<li><sf:checkbox path="invalidStreetAddress"/> Invalid Street Address</li>
<li><sf:checkbox path="invalidSubName" /> Invalid Sub Name</li>
</ul>
</li>
<li>
<c:choose>
<c:when test="${invalidDropForm.derogatoryNames==true && invalidDropForm.businessNames==true && invalidDropForm.offensiveNames==true}">
<input type="checkbox" class="check-inside invalidOffensive" id="invalidOffensive" checked/> Offensive, Derogatory, Business Names
</c:when>
<c:otherwise>
<input type="checkbox" class="check-inside invalidOffensive" id="invalidOffensive"/> Offensive, Derogatory, Business Names
</c:otherwise>
</c:choose>
<ul class="inneritem">
<li><sf:checkbox path="derogatoryNames" /> Derogatory Names</li>
<li><sf:checkbox path="businessNames" /> Business Names</li>
<li><sf:checkbox path="offensiveNames" /> Offensive Names</li>
</ul>
</li>
</ul>
答案 0 :(得分:0)
in text:...如果页面中的另一个复选框&#34; .invalidOffensive&#34;没有选中
代码中的:...&amp;&amp; ($(&#39; .invalidOffensive&#39)的。是(&#39;:检查&#39)强>)