Here is my script of function to retrieve the properties of checkboxes:
var checkedCount = 0;
$('input.new-checkbox').each(function() {
console.log('checked : ' + $(this).prop('checked')); // returned false
console.log('disabled : ' + $(this).prop('disabled')); // returned false
console.log('checked : ' + this.checked); // returned false
console.log('disabled : ' + $(this).attr('disabled')); // returned undefined
console.log('checked : ' + $(this).is(':checked')); // returned false
console.log('disabled : ' + $(this).attr('disabled')); // returned undefined
console.log('checked : ' + $(this).attr('checked')); // returned undefined
if($(this).prop('checked') == true)
{
checkedCount = checkedCount + 1;
}
});
Here is the script of function how I disable and check a checkbox, where arrayA is an array:
$('input.new-checkbox').each(function() {
for(var i=0; i<arrayA.length; i++)
{
if($(this).val() == arrayA[i])
{
// set the checkbox checked
$(this).prop('checked', true);
// disable the checkbox
$(this).prop('disabled', true);
}
}
});
I check each checkbox if its value equals to the value in array, then set the checkbox checked and disable it.
When I click/check the checkbox, it returns me the state of the prop('checked') and prop('disabled') correctly. But when it already been disabled and checked, it gives me 'false' for both 'checked' and 'disabled' properties.
Anybody know why is this happened?
Aucun commentaire:
Enregistrer un commentaire