Home > Web Front-end > JS Tutorial > body text

How to determine whether checkbox is selected in jquery

coldplay.xixi
Release: 2020-12-04 11:04:38
Original
2838 people have browsed it

Jquery method to determine whether the checkbox is selected: 1. Use the [.attr('checked)] method; 2. Use the [.prop('checked')] method; 3. Use [.is(': checked')] method.

How to determine whether checkbox is selected in jquery

The operating environment of this tutorial: windows7 system, jquery3.2.1 version. This method is suitable for all brands of computers.

How jquery determines whether the checkbox is selected:

Three ways jquery determines whether it is checked:

  • .attr('checked): //Look at version 1.6, return: "checked" or "undefined"; 1.5-return: true or false

  • ##.prop('checked'): //16 :true/false

  • .is(':checked'): //All Version: true/false//Don’t forget the colon

Several ways to write jquery assignment checked:

All jquery versions can be like this Assignment:

// $("#cb1").attr("checked","checked");
// $("#cb1").attr("checked",true);
Copy after login

jquery1.6: 4 types of assignment of prop:

    // $("#cb1″).prop("checked",true);//很简单就不说了哦
    // $("#cb1″).prop({checked:true}); //map键值对
    // $("#cb1″).prop("checked",function(){
      return true;//函数返回true或false
    });
Copy after login

Remember there is this one:

$("#cb1″).prop("checked","checked");
Copy after login

Related learning recommendations:

javascript video tutorial

The above is the detailed content of How to determine whether checkbox is selected in jquery. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template