The prop and attr of the selection problem of JQuery checkbox

Source: Internet
Author: User

$( function () {    // 全选    $( "#btnCheckAll" ).bind( "click" , function () {      $( "[name = chkItem]:checkbox" ).attr( "checked" , true );    });    // 全不选    $( "#btnCheckNone" ).bind( "click" , function () {      $( "[name = chkItem]:checkbox" ).attr( "checked" , false );    });    // 反选    $( "#btnCheckReverse" ).bind( "click" , function () {      $( "[name = chkItem]:checkbox" ).each( function () {        $( this ).attr( "checked" , !$( this ).attr( "checked" ));      });    });    // 全不选    $( "#btnSubmit" ).bind( "click" , function () {      var result = new Array();      $( "[name = chkItem]:checkbox" ).each( function () {        if ($( this ).is( ":checked" )) {          result.push($( this ).attr( "value" ));        }      });      alert(result.join( "," ));    }); });

Problem Description: The first point to select All can, and then click on the whole selection, then click on the Select all, all do not select, the reverse selection will not react, and later with other browsers to send can, so the feeling is compatibility problem, later access to the data found that is true, reference address http://jquery.com/

Solution: Change the attr to prop can, after verifying that each browser is good, the official website is recommended after 1.6 with prop, in this record for later use.

JQuery checkbox Check prop and attr attention point analysis

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.