How to obtain the value of the check box in jquery _ jquery-js tutorial

Source: Internet
Author: User
There are many ways to get the value of a check box. This article will show you how jquery gets the value of a check box. Do not miss it if you are interested. The Code is as follows:






JS to obtain the selected value of the check box


0
1
2
3
4
5
6
7



JS Code

The Code is as follows:





Other operations on the checkbox

1. Select All
2. Cancel all selections
3. Select All odd numbers
4. Invert Selection
5. Obtain all selected values

Js Code

The Code is as follows:



$ ("Document"). ready (function (){
$ ("# Btn1"). click (function (){
$ ("[Name = 'checkbox']"). attr ("checked", 'true'); // select all
})
$ ("# Btn2"). click (function (){
$ ("[Name = 'checkbox']"). removeAttr ("checked"); // cancel all
})
$ ("# Btn3"). click (function (){
$ ("[Name = 'checkbox']: even"). attr ("checked", 'true'); // select all odd numbers
})
$ ("# Btn4"). click (function (){
$ ("[Name = 'checkbox']"). each (function () {// reselect
If ($ (this). attr ("checked ")){
$ (This). removeAttr ("checked ");
}
Else {
$ (This). attr ("checked", 'true ');
}
})
})
$ ("# Btn5"). click (function () {// output the selected value
Var str = "";
$ ("[Name = 'checkbox'] [checked]"). each (function (){
Str + = $ (this). val () + "/r/n ";
// Alert ($ (this). val ());
})
Alert (str );
})
})


Html code:

The Code is as follows:






Louis-blog> jQuery operations on checkbox

Related Article

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.