1.什么是attribute,什么是property属性?
attribute: html自定义属性 和预定义属性
property: js原生对象的直接属性
每一个预定义的attribute都会有一个property与之对应
2.什么是布尔值属性,什么是非布尔值属性?
property所对应的值是否为布尔值类型
3.attribute和property同步关系
非布尔值属性: 实时同步
布尔值属性:
没有动过property,attribute会同步property,property不会同步attribute
动过property,都不会同步
4.用户操作的是property
浏览器认property
5.Jquery中两个方法attr()
prop()
布尔值属性最好使用prop方法
非布尔值属性attr方法
<input type="checkbox" checked="checked" name="lyp" /> <!--checked既是input标签的attribute(对于html),又是input节点的property(对于js)-->
<script type="text/javascript">
var l= document.querySelector("input[type=checkbox]")
//布尔值属性:你的property是布尔值类型 checked就是布尔值属性 改变property不会同步attribute
debugger
l.setAttribute("checked","checked1") //操作标签的attribute
l.setAttribute("checked","checked2")
l.checked = true
l.checked = "checked3" //操作节点的property
l.checked = "checked4"
debugger
//非布尔值属性:你的property是非布尔值类型 name就是非布尔值属性 在非布尔值属性里面,property和attribute会实时同步
l.setAttribute("name",'lalala')
l.name = "heheh"
//浏览器只认property
</script>