我的Jquery Checkbox菜单有一些问题,没有复选框菜单。
当我检查示例windows top复选框然后检查php复选框并取消选中windows复选框并再次检查它没有选中php复选框。
我想在支持标签上添加相同的功能,它还应该对其子项复选框进行计数。
这是我的代码:http://jsfiddle.net/H2z9G/4/
HTML应保持完整。
Jquery的:
$('.payload').hide();
$('.checkGroup > input[type="checkbox"]').live('change',function(){
$t = $(this);
$t.closest('.checkGroup').find('.payload').toggle( $t.is(':checked'));
if( !$t.is(':checked') ){
$t.closest('.checkGroup').find('.payload input[type="checkbox"]')
.attr('checked',false);
}
}).trigger('change');
$('.checkGroup input[type="checkbox"]').change(function(){
$c = $(this);
$c.closest('.checkGroup').find('label > span b').text( $c.closest('.checkGroup').find('input[type="checkbox"]:checked').length );
}).trigger('change');
HTML:
<div class="checkGroup">
<label for="search_windows_is_true"><span style="font-size: 12px; padding-top: 6px;">WINDOWS<b>0</b></span></label>
<input type="hidden" value="0" name="search[windows_is_true]"><input type="checkbox" value="1" name="search[windows_is_true]" id="search_windows_is_true">
<div class="payload" style="display: none;">
<label style="background: none repeat scroll 0pt 0pt rgb(255, 255, 255); border-bottom: 1px solid rgb(51, 51, 51); border-top: 1px solid rgb(51, 51, 51); height: 20px; margin: 0pt;">
<span style="font-size: 12px; padding-top: 6px; font-weight: bold;">PHP</span>
<input type="hidden" value="0" name="search[php_is_true]"><input type="checkbox" value="1" style="top: 4px;" name="search[php_is_true]" id="search_php_is_true">
</label>
</div>
</div>
<div class="checkGroup">
<label for="search_windows_is_true"><span style="font-size: 12px; padding-top: 6px;">WINDOWS<b>0</b></span></label>
<input type="hidden" value="0" name="search[windows_is_true]"><input type="checkbox" value="1" name="search[windows_is_true]" id="search_windows_is_true">
<div class="payload" style="display: none;">
<label style="background: none repeat scroll 0pt 0pt rgb(255, 255, 255); border-bottom: 1px solid rgb(51, 51, 51); border-top: 1px solid rgb(51, 51, 51); height: 20px; margin: 0pt;">
<span style="font-size: 12px; padding-top: 6px; font-weight: bold;">PHP</span>
<input type="hidden" value="0" name="search[php_is_true]"><input type="checkbox" value="1" style="top: 4px;" name="search[php_is_true]" id="search_php_is_true">
</label>
</div>
</div>
<div class="nonecheckGroup">
<label for="search_windows_is_true"><span style="font-size: 12px; padding-top: 6px;">Support<b>0</b></span></label>
<div class="payload" style="display: none;">
<label style="background: none repeat scroll 0pt 0pt rgb(255, 255, 255); border-bottom: 1px solid rgb(51, 51, 51); border-top: 1px solid rgb(51, 51, 51); height: 20px; margin: 0pt;">
<span style="font-size: 12px; padding-top: 6px; font-weight: bold;">PHP</span>
<input type="hidden" value="0" name="search[php_is_true]"><input type="checkbox" value="1" style="top: 4px;" name="search[php_is_true]" id="search_php_is_true">
</label>
</div>
</div>