About the differences between prop and attr in the jquery form selection.

Source: Internet
Author: User

today, with the jquery learning form, this section of the chapter, once again encountered the full selection of the form, can not be a second full-time situation. There is still no reason to see the test repeatedly. Later on the Internet to find that the original is jQuery1.6 after the version used is prop. Using attr will not be implemented more than once, because attr does not record the current checkbox's selected state.

This chapter of the form makes me feel a little hard, in short, good work!

Here is the code description:

<! DOCTYPE html>    $(function(){        //using attr        /*$ ("#CheckedAll"). Click (function () {if (this.checked) {$ (' [Name=items]:checkbox ')]. attr (' Checke            d ', false);            } else {$ (' [Name=items]:checkbox '). attr (' checked ', true); }        });*/        //using prop$ ("#CheckedAll"). Click (function(){            if( This. Checked) {                $(' [Name=items]:checkbox '). Prop (' checked '),false); } Else {                $(' [Name=items]:checkbox '). Prop (' checked '),true); }        });*/            }); </script>What's your favorite sport? <br> <input type= "checkbox" name= "items" value= "soccer" >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" > table tennis <br> <input type= "button" id= "Checkedall" value= " Select All "> <input type=" button "id=" Checkedno "value=" Select All "> <input type=" button "id=" Checkedrev "Valu e= "Reverse Selection" > <input type= "button" id= "send" value= "submit" > </form></body>

For the distinction between attribute and property, refer to: HTTP://WWW.TUICOOL.COM/ARTICLES/3UUQRR6

About the differences between prop and attr in the jquery form selection.

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.