jQuery的prop和attr方法之间区别
JQuery.attr():
Get the value of an attribute for the first element in the set of matched elements.
JQuery. Prop():
Gets the value of a property for the first element in the set of matched elements.
Reference MSDN:
for a checkbox (jquery 1.6+)
<input id="check1" checked="checked" type="checkbox" />
.attr('checked') //returns checked
.prop('checked') //returns true
.is(':checked') //returns true
Prop() method returns Boolean value for checked, selected, disabled, readOnly..and so on while attr returns defined string. So, you can directly use .prop("checked") in if condition. SelectedIndex, tagName, nodeName, nodeType, ownerDocument, defaultChecked, and defaultSelected..and so on should be retrieved and set with the .prop() method. These do not have corresponding attributes and are only properties. .attr() calls .prop() internally so .attr() method will be slightly slower than accessing them directly through .prop().
一些内容(摘录来自网络)。
相关文章
- Jquery控制滚动Div 滚动条事件
- 35个Jquery应用实例
- Jq_DOM元素方法跟JQuery 核心函数跟JQuery 事件方法
- jQuery的事件change
- jQuery简单实现iframe的高度根据页面内容自适应的方法(转)
- js/jquery判断浏览器的方法小结
- jQuery根据元素值或元素下标来删除一个数组元素及数组对象方法列表
- Web jquery表格组件 JQGrid 的使用 - 4.JQGrid参数、ColModel API、事件及方法
- jQuery on()方法
- 使用jquery.form.js的ajaxsubmit方法提交数据的Bug
- jQuery操作表格(table)的常用方法、技巧汇总
- jQuery 人脸识别插件,支持图片和视频
- Web 前端开发精华文章推荐(HTML5、CSS3、jQuery)【系列二十二】
- .NET(C#) 使用CsQuery后台通过JQuery语法解析Html方法代码
- ASP.NET MVC的客户端验证:jQuery验证在Model验证中的实现
- 基于jQuery扁平多颜色选项卡切换代码
- jQuery向父辈遍历的方法
- JQuery中$.load()方法的用法和分析【转】