方法一: if ($("#checkbox-id")get(0).checked) { // do something } 方法二: if($('#checkbox-id').is(':checked')) { // do something } 方法三: if ($('#checkbox-id').attr('checked')) { // do something }
最近项目中需要用jquery判断input里checkbox是否被选中,发现用attr()获取不到复选框改变后的状态,最后查资料发现jQuery 1.6以后新增加了prop()方法,借用官方的一段描述就是: The difference between attributes and properties can be important in specific situations. Before jQuery 1.6, the .attr() method sometimes took pro