event.target.propertyName和event.target.getAttribute("propertyName")区别

来源:互联网 发布:ubuntu安装jdk eclipse 编辑:程序博客网 时间:2024/06/05 23:06
getAttribute拿的是html属性的值,而prop是DOM接口,存取如何是由DOM规范定义的,跟html上的值是不一定对应的。比如 input.value 你可以改变,但是 input.getAttribute('value') 你拿到的总是html上的属性的值,是不变的。再如 a.href 得到总是绝对地址,而 a.getAttribute('value') 则是 html上写的地址,原来是什么就是什么。



链接:https://www.zhihu.com/question/25313868/answer/30430792

原创粉丝点击