How to realize the inverse method in jquery
This article mainly explains "how to realize the inverse method of jquery". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "how to achieve the reverse method of jquery"!
Jquery to achieve reverse methods: 1, import jQuery library; 2, set click events; 3, cycle to set other multi-check box selected state; 4, through the "! chkall;" way to achieve the identification variable can be reversed.
This article operating environment: windows7 system, jquery-2.1.4 version, Dell G3 computer.
How does jquery implement the inversion method?
Several methods of realizing full selection and reverse selection by using JQuery
As shown in the figure: the effect to be achieved is to click the full box to select all, and then click to uncheck all.
Method one idea: 1, import jQuery library, this can be downloaded online, is free and open source, 2, set class to fruit, set their properties through prop.
Method 1: jQuery code:
/ / define the identity. True means to select var chkall = true; $(function () {/ / all button to set the click event $("# btnAll") .click (function () {/ / 1), cycle to set other multi-check box check states, which are the same as the variables used in the logo: $(".check") .prop ("checked", chkall) / / 2. The identified variable is chkall =! chkall;})})
The second way of thinking: get all the checkboxes through the form filter and cycle through setting the checked property.
Method 2: jQuery code:
$(function () {/ / get the value of the full marquee var $checked = this.checked; / / get all the marquee $("input [class=fruit]") .each (function () {/ / the value of the checkbox is consistent with the value of the full marquee this.checked = $checked })
Finally, it is added that JQuery generally uses Attr to get the property, and sets the value of the property with prop.
At this point, I believe you have a deeper understanding of "how to achieve the inverse method of jquery". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!