jquery获得checkbox是否选中的状态
来源:互联网 发布:电子书包软件 编辑:程序博客网 时间:2024/04/30 16:53
Concerning boolean attributes, consider a DOM element defined by the HTML markup<input type="checkbox" checked="checked" />
, and assume it is in a JavaScript variable namedelem
:
elem.checked
true
(Boolean) Will change with checkbox state$(elem).prop("checked")
true
(Boolean) Will change with checkbox stateelem.getAttribute("checked")
"checked"
(String) Initial state of the checkbox; does not change$(elem).attr("checked")
(1.6)"checked"
(String) Initial state of the checkbox; does not change$(elem).attr("checked")
(1.6.1+)"checked"
(String) Will change with checkbox state$(elem).attr("checked")
(pre-1.6)true
(Boolean) Changed with checkbox state
注意:elem.getAttribute("checked")和$(elem).attr("checked");都是获得checkbox的初始的状态,并且不会因为你是否勾选而改变状态,所以判断checkbox是否勾选不能用这2个方法
According to the W3C forms specification, the checked
attribute is a boolean attribute, which means the corresponding property istrue if the attribute is present at all—even if, for example, the attribute has no value or is set to empty string value or even "false". This is true of all boolean attributes.
Nevertheless, the most important concept to remember about thechecked
attribute is that it does not correspond to the checked
property.The attribute actually corresponds to the defaultChecked
property and should be used only to set theinitial value of the checkbox. The checked
attribute value does not change with the state of the checkbox, while thechecked
property does. Therefore, the cross-browser-compatible way to determine if a checkbox is checked is to use the property:
最重要的概念是记住checked attribute不相当于checked property!checked attribute不会随着checkbox状态而改变,而checked property 会
if ( elem.checked )
if ( $(elem).prop("checked") )
if ( $(elem).is(":checked") )
The same is true for other dynamic attributes, such as selected
andvalue
参考:http://api.jquery.com/prop/
- jquery获得checkbox是否选中的状态
- jQuery获取checkbox是否选中的状态
- jquery判断checkbox是否选中及改变checkbox状态
- jquery判断checkbox是否选中及改变checkbox状态
- jquery判断checkbox是否选中及改变checkbox状态
- jquery判断checkbox是否选中及改变checkbox状态
- jquery判断checkbox是否选中及改变checkbox状态 oncheck
- jquery判断checkbox是否选中及改变checkbox状态
- jquery判断checkbox是否选中及改变checkbox状态
- jquery判断checkbox是否选中及改变checkbox状态
- jquery判断checkbox是否选中及改变checkbox状态
- jquery判断checkbox是否选中及改变checkbox状态
- jquery判断checkbox是否选中及改变checkbox状态
- jquery判断checkbox是否选中及改变checkbox状态
- jquery判断checkbox是否选中及改变checkbox状态
- jquery判断checkbox是否选中及改变checkbox状态
- jquery判断checkbox是否选中及改变checkbox状态
- jquery判断checkbox是否选中及改变checkbox状态
- hibernate注解(三)
- 如何去建立Linux企业集群
- PHP根据IP判断地区名信息
- 离开团队,你将什么都不是
- Django学习笔记—获取正确的客户端IP地址
- jquery获得checkbox是否选中的状态
- Fragments For All
- Android 4.0 Launcher2源码分析——Workspace滑动
- Linux 系统的兼容性问题
- 双机热备解决方案--思路
- Java的short,int,long
- properties文件内容转码-native2ascii
- PHP实现即时输出信息
- 类型“Microsoft.Office.Interop.Word.ApplicationClass”未定义构造函数