jquery operation checkbox (multi box)

Source: Internet
Author: User

problem: JQ is used at work uery operation of the Multi-box (checkbox) Knowledge, the previous records and notes to find out the direct use, but the problem arises, deselect, select the specified multi-box again, with the browser (F12) is added checked property, but the page display is not selected (no tick) , here's a summary of how to solve the problem.

Here's a solution (using jquery version 2.1.3):

1. Static page checkbox.html (Note: You must add the Select attribute to the check tag)

<! DOCTYPE html>2, JS file Multi-Select, deselect and reverse (checkbox.js)

function SelectAll () {$ ("input[name= ' CheckBox1 ')"). each (function () {  $ (this). Prop ("checked", true);}); function Fanxuan () {$ ("input[name= ' CheckBox1 ')"). each (function () {if ($ (). Prop ("checked") = = True) {alert ($ (this) . attr ("checked"));    $ (this). Prop ("checked", false);} Else{alert ($ (this). attr ("checked"));    $ (this). Prop ("checked", true);});} function Cancelselect () {$ ("input[name= ' CheckBox1 ')"). each (function () {  $ (this). Prop ("checked", false);});
Here to use the time Prop property, the following analysis of the reasons, in order to avoid the re-build wheel, we can go to the following two articles to look at:

Refer to the differences between attr and prop in article 1:jquery

Reference article 2:jquery the difference between attr method and prop method

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

jquery operation checkbox (multi box)

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.