I tried this script, to create a custom checkbox with the name parameter.
function customCheckbox(checkboxName){
var checkBox = $('input[name="'+ checkboxName +'"]');
$(checkBox).each(function(){
$(this).wrap( "<span class='custom-checkbox'></span>" );
if($(this).is(':checked')){
$(this).parent().addClass("selected");
}
});
$(checkBox).click(function(){
$(this).parent().toggleClass("selected");
});
}
$(document).ready(function (){
customCheckbox("name1");
customCheckbox("name2");
})
display looks good on css. then I want to make a checkbox for checkall and uncheckall .. I tried this script ...
$("#checkAll").click(function(){
$('input:checkbox').not(this).prop('checked', this.checked);
});
only the default checkbox successful. Custom checkbox mine was not working. please help fix.
simple html
<label><input type='checkbox' id='checkAll' name='name1' class='selectall' /></label>
<label><input type="checkbox" name="name2" value="1" /> 1</label>
<label><input type="checkbox" name="name2" value="2" /> 2</label>
<label><input type="checkbox" name="name2" value="3" /> 3</label>
<label><input type="checkbox" name="" value="4" /> 4</label>
<label><input type="checkbox" name="" value="5" /> 5</label>
Aucun commentaire:
Enregistrer un commentaire