Home > Web Front-end > JS Tutorial > body text

Summary of 12 tips for operating checkboxes in jquery_jquery

WBOY
Release: 2016-05-16 17:01:23
Original
950 people have browsed it

1. Get a single checkbox selected item (three writing methods)
$("input:checkbox:checked").val()
or
$("input: [type='checkbox']:checked").val();
or
$("input:[name='ck']:checked").val();

2. Get multiple checkbox selected items
$('input:checkbox').each(function() {
                                                                                 ) ==true) {
                                                                                                   

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 as the selected value

$('input:radio:last').attr('checked', 'checked'); or
$('input:radio:last').attr('checked', 'true');


5. Set any checkbox as the selected value according to 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 checkboxes and select the 1st and 2nd checkboxes at the same time

$('input:radio').slice(0,2).attr('checked' ,'true');
7. Set the checkbox to the selected value according to the Value value

$("input:checkbox[value='1']").attr('checked','true');
8. Delete the checkbox with Value=1

$("input:checkbox[value='1']").remove();
9. Which checkbox to delete?

$("input:checkbox").eq(index value).remove(); index value=0,1,2.... To delete the third checkbox:
$("input:checkbox").eq(2).remove();


10. Traverse checkbox

$('input:checkbox').each(function (index, domEle) {//Write code
});


11. Select all

$('input:checkbox').each(function() {                                                                                                               >});

12. Unselect all

$('input:checkbox').each(function () {

                                                                              🎜>});

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!