jquery中attr和prop的区别

对于HTML元素本身就带有的固有属性,在处理时,使用prop方法。
对于HTML元素我们自己自定义的DOM属性,在处理时,使用attr方法。

<input id="chk2" type="checkbox" checked="checked"  action="delate"/>

以上HTML中JQ获取属性

alert($("#chk2").prop("checked"));//true ,如果用attr那么就是undefined
alert($("#chk2").attr("action"));//true,如果用prop那么就是undefined

原文地址:https://www.cnblogs.com/binmengxue/p/8521564.html