Function Code (ODD) _ jquery

Source: Internet
Author: User
Jquery implements the functions such as full selection, reverse selection, and no selection. The following example describes the functions. For more information, see the following set of check boxes and related buttons on the page, all are not selected ):

The Code is as follows:


Apple
Orange
Bananas
Grape






The complete code for implementing the relevant functions is as follows:

The Code is as follows:


$ (Function (){
$ ('# Btn1'). click (function () {// select all
$ ("[Name = 'fruit']"). attr ('checked', 'true ');
});
$ ('# Btn2'). click (function () {// none
$ ("[Name = 'fruit']"). removeAttr ('checked ');
});
$ ('# Btn3'). click (function () {// reselect
$ ("[Name = 'fruit']"). each (function (){
If ($ (this). attr ('checked ')){
$ (This). removeAttr ('checked ');
} Else {
$ (This). attr ('checked', 'true ');
}
})
});
$ ("# Btn4"). click (function () {// select all odd numbers
$ ("[Name = 'fruit']: even"). attr ('checked', 'true ');
})
$ ("# Btn5"). click (function () {// obtain the values of all selected options
Var checkVal = '';
$ ("[Name = 'fruit'] [checked]"). each (function (){
CheckVal + = $ (this). val () + ',';
})
Alert (checkVal );
})
});


Before using jquery, you must introduce the jquery package!
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.