Wetts's blog

Stay Hungry, Stay Foolish.

0%

JavaScript-区别-dom.getAttribute(value)和dom.value

dom 是一个 input type=”text”

手动修改 input 的值,使用 dom.getAttribute("value") 只能得到 html Dom中的值,而不能得到修改后的值(即内存中的值); 

可以通过 dom.value 得到修改后的最新值(内存中的值)
 
使用:dom.setAttribute("value","2011") ,只能通过 dom.getAttribute("value") 得到 2011

使用: dom.value = 2012 ,只能通过 dom.value 得到 2012
 
也就是说: getAttribute 和 setAttribute 是一套, 直接使用属性是一套,两套完成不是一回事。

jQuery 底层的方法 $.fn.val() 使用的是  dom.value 属性。