1. jquery determines whether the checkbox is selected and changes the checkbox status
Three ways to determine checked in jquery:
2. How does jquery determine whether a checkbox is selected
Everyone knows that in html if a checkbox is checked it is checked="checked".
But if we use jquery alert($("#id").attr("checked")), it will prompt you that it is true instead of checked
So many friends judge that if($("#id").attr("checked")=="true") is wrong. In fact, it should be if($("#id").attr(" checked")==true)
The example includes several functions.
三、 jquery判断checkbox是否被选中
在html的checkbox里,选中的话会有属性checked="checked"。
如果用一个checkbox被选中,alert这个checkbox的属性"checked"的值alert($"#xxx".attr("checked")),会打印出"true"",而不是checked"!
如果没被选中,打印出的是"undefined"。
不要尝试去做这样的判断:if($"#xxx".attr("checked")=="true")或者if($"#xxx".attr("checked")=='checked')
应该是if($("#checkbox1").attr("checked")==true)
全选和全不选函数
4. JQuery determines whether the checkbox is selected, selects all checkboxes, and obtains the checkbox selected value
JQuery is a very easy to use framework, but there are many things that we need to learn in depth.
There are many ways to judge whether the checkbox is selected online. Here is one method. Personally I think
More convenient.
Because it is relatively simple and has no technical content, just code it directly