jQuery Operation Check Box of CheckBox Value Assignment Implementation Code
- 2021-07-10 18:13:04
- OfStack
1. Get a single checkbox check (written in three ways):
$("input:checkbox:checked").val()
Or
$("input:[type='checkbox']:checked").val();
Or
$("input:[name='ck']:checked").val();
2. Get multiple checkbox selections:
$('input:checkbox').each(function() {
if ($(this).attr('checked') ==true) {
alert($(this).val());
}
});
3. Set the first checkbox to the selected value:
$('input:checkbox:first').attr("checked",'checked');
Or
$('input:checkbox').eq(0).attr("checked",'true');
4. Set the last checkbox to the selected value:
$('input:radio:last').attr('checked', 'checked');
Or
$('input:radio:last').attr('checked', 'true');
5. Set any 1 checkbox to the selected value based on the index value:
$('input:checkbox).eq( Index value ).attr('checked', 'true'); Index value =0,1,2....
Or
$('input:radio').slice(1,2).attr('checked', 'true');
6. Select multiple checkbox:
Select both checkbox 1 and 2:
$("input:[type='checkbox']:checked").val();
0
7. Set checkbox to the selected value based on the Value value:
$("input:[type='checkbox']:checked").val();
1
8. Delete checkbox for Value=1:
$("input:[type='checkbox']:checked").val();
2
9. Which checkbox to delete:
$("input:checkbox").eq( Index value ).remove(); Index value =0,1,2....
If you delete the 3 A checkbox:
$("input:checkbox").eq(2).remove();
10. Traverse checkbox:
$("input:[type='checkbox']:checked").val();
4
11. Select All
$("input:[type='checkbox']:checked").val();
5
12. Deselect All:
$("input:[type='checkbox']:checked").val();
6