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 />

 

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

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

相关文章:

  • 2022-12-23
  • 2021-07-26
  • 2021-04-12
猜你喜欢
  • 2022-12-23
  • 2021-10-22
  • 2021-11-20
  • 2021-07-27
  • 2021-08-17
相关资源
相似解决方案