Home > Web Front-end > JS Tutorial > Various methods for jquery to operate checked attributes and disabled attributes_jquery

Various methods for jquery to operate checked attributes and disabled attributes_jquery

WBOY
Release: 2016-05-16 16:43:46
Original
1700 people have browsed it

There is no difference between the two ways of writing below, it’s just that some code is missing...

Copy code The code is as follows:



Three ways to determine checked in jquery:

Copy code The code is as follows:

.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 versions: true/false//Don’t forget the colon

Several ways to write jquery assignment checked:

All jquery versions can be assigned like this:

Copy code The code is as follows:

$("#cb1").attr("checked","checked");
$("#cb1").attr("checked",true);

jquery1.6: 4 types of assignment of prop:

Copy code The code is as follows:

$("#cb1").prop("checked",true); //It’s very simple so I won’t go into details
$("#cb1").prop({checked:true}); //map key-value pair

$("#cb1").prop("checked",function(){
Return true; //The function returns true or false
});

$("#cb1").prop("checked","checked");

More references: http://api.jquery.com/prop/

Copy code The code is as follows:



                                                                                                       

            

Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template