jquery prop () method to solve the problem of selecting the Select All-in-one option to resolve execution once

Source: Internet
Author: User

1. If you change the Type property of the <input> and <button> elements through the prop () function, an error will be thrown on most browsers because this property is generally not allowed to be changed at a later time.
If you use the Prop () function to manipulate properties such as the checked, selected, disabled, and so on of the form element, returns True if the element is selected (or disabled), otherwise (meaning that there is no property in HTML) to return FALSE.
3. The prop () function can also set or return certain properties on the element object of the DOM elements, for example: TagName, SelectedIndex, NodeName, NodeType, Ownerdocument, Attributes such as defaultchecked and defaultselected.
In IE9 and earlier versions, if the property value set with the prop () function was not a simple original value (String, number, Boolean), and the property was not removed before the corresponding DOM element was destroyed, a memory leak issue could result. If you are just trying to store data, it is recommended that you use data () functions to avoid memory leak issues.
$(function () {       $("#j_cbAll"). Click (function () {           //If the Select All button is selected then all the buttons are selected above have prop usage use the Prop () method to resolve the issue after the execution once can no longer select all$ ("#j_tb: CheckBox"). Prop ("Checked", $ ( This). Prop ("Checked"));       }); $("#j_tb: CheckBox"). Click (function() {Singleclick ();      }); $("#fanxuan"). Click (function () {          $("#j_tb: CheckBox"). each (function () {              //Inverse Selection$( This). Prop ("Checked",!$ ( This). Prop ("Checked"));          Singleclick ();      });       }); //If a checkbox is not selected, select all unchecked if the sub's checkbox is selected, select All       functionSingleclick () {//if the child element is not selected, select all unchecked           if(!$ ("#j_tb: CheckBox"). Checked) {$ ("#j_cbAll"). Prop ("Checked",false); }           //Number of checkboxes           varChsub = $ ("#j_tb: CheckBox"). length; //the number of checkboxes selected           varCheckedsub = $ ("#j_tb: checkbox:checked"). length;
Determine if the number of choices is the same as all numbersif(Checkedsub = = =chsub) {
The Select All button is selected for the $ ("#j_cbAll"). Prop ("Checked",true); }; } });

<! DOCTYPE html>{padding: 0; Margin: 0;}. Wrap{width: 300px; Margin: 100px Auto 0;} table{Border-collapse: Collapse; Border-spacing: 0; Border: 1px solid #c0c0c0; Width: 300px;} TH, TD{border: 1px solid #d0d0d0; Color: #404060; Padding: 10px;} th{Background-color: #09c; Font: Bold 16px "Microsoft Ya Hei"; Color: #fff;} TD{font: 14px "Microsoft Ya Hei";} tbody TR{Background-color: #f0f0f0;} tbody Tr:hover{cursor: pointer; Background-color: #fafafa;} </style> <script src= ". /js/jquery-1.12.4.js "></script>


jquery prop () method solves the problem of selecting an all-in-one option to resolve execution once no more problems can be performed

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.