<label><input type="checkbox" name="" /> Normal</label>
<label><input type="checkbox" name="" checked="checked" /> Checked</label>
<label><input type="checkbox" name="" disabled="disabled" /> Disabled</label>
If the checkbox is 'checked', its label should have class 'checked', same for 'disabled'.
I tried this, but doesn't seem to work:
$("input[type=checkbox][checked]").each(
function(开发者_JAVA技巧) {
$(this).parent().addClass('checked');
}
);
http://jsfiddle.net/eJfT6/
Thanks for your help!
You can test this:
$('input:checkbox').each(function(){
if($(this).is(':checked')){
$(this).parent().addClass('checked');
}
if($(this).is(':disabled')){
$(this).parent().addClass('disabled');
}
});
try this one....
$("input[type=checkbox][checked]").each(
function() {
$(this).parent().addClass('checked');
}
);
// for disabled
$("input[type=checkbox]").each(
function() {
if( $(this).attr('disabled')){
alert("in side");
$(this).parent().addClass('checked');
}
}
);
you can merge both function i have seprated it just for your understanding.
http://jsfiddle.net/Htcjb/
精彩评论