属性.value
<body> <input type="text" name="test" value="123" /> <p onclick="fun();">点我获取值</p> <script type="text/javascript"> function fun(){ alert(document.getElementsByTagName("input")[0].value); alert(document.getElementsByTagName("input")[0].getAttribute("value")); } </script> </body>
.value和.getAttribute 是有区别的
手动修改 input 的值, 使用 dom.getAttribute("value") 只能得到 html Dom中的值,而不能得到修改后的值(即内存中的值);
可以通过 dom.value 得到修改后的最新值(内存中的值)