Home > Article > Web Front-end > How to determine whether checkbox is selected in jquery
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.
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);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 });Remember there is this one:
$("#cb1″).prop("checked","checked");
Related learning recommendations:
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!