您的位置:威尼斯城vnsc登入平台 > 网络信息 > jQuery的prop和attr方法之间区别

jQuery的prop和attr方法之间区别

2019-11-24 09:51

jQuery的prop和attr方法之间区别,jqueryattr

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().

 
一些内容(摘录来自网络)。

http://www.bkjia.com/jQuery/965068.htmlwww.bkjia.comtruehttp://www.bkjia.com/jQuery/965068.htmlTechArticlejQuery的prop和attr方法之间区别,jqueryattr JQuery.attr(): Get the value of an attribute for the first element in the set of matched elements. JQuery. Prop(): Gets the valu...

JQuery.attr():
Get the value of an attribute for the first element in the set of matched elements.

.attr('checked')     //returns checked
.prop('checked')     //returns true
.is(':checked')     //returns true

 

 

 

本文由威尼斯城vnsc登入平台发布于网络信息,转载请注明出处:jQuery的prop和attr方法之间区别

关键词:

  • 上一篇:没有了
  • 下一篇:没有了