Select All check boxes

Source: Internet
Author: User

<SCRIPT type = "text/JavaScript">
$ (Function (){
// Select all
$ ("# Checkedall"). Click (function (){
// All the checkboxes follow the all selected checkboxes.
$ ('[Name = items]: checkbox'). ATTR ("checked", this. Checked );
});
$ ('[Name = items]: checkbox'). Click (function (){
// Define a temporary variable to avoid repeated use of the same selector to select elements on the page, improving program efficiency.
VaR $ TMP = $ ('[name = items]: checkbox ');
// Use the filter method to filter out the selected check boxes. And assign a value to checkedall.
$ ('# Checkedall'). ATTR ('checked', $ TMP. Length = $ TMP. Filter (': checked'). Length );

/*
// Write more comments for a row that does too many tasks. Complex selectors may also affect efficiency. Therefore, the following statement is not recommended.
$ ('# Checkedall'). ATTR ('checked ',! $ ('[Name = items]: checkbox'). Filter (': Not (: checked) '). Length );
*/
});
// Output value
$ ("# Send"). Click (function (){
VaR STR = "you selected: \ r \ n ";
$ ('[Name = items]: checkbox: checked'). Each (function (){
STR + = $ (this). Val () + "\ r \ n ";
})
Alert (STR );
});
});
</SCRIPT>

 

<Form method = "Post" Action = "">
What kind of sports do you like? <Input type = "checkbox" id = "checkedall"/> select all or not <br/>
<Input type = "checkbox" name = "items" value = ""/> football
<Input type = "checkbox" name = "items" value = "basketball"/> basketball
<Input type = "checkbox" name = "items" value = "badminton"/> Badminton
<Input type = "checkbox" name = "items" value = ""/> Table Tennis <br/>
<Input type = "button" id = "send" value = "Submit"/>
</Form>

Select All check boxes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.