無法得到爲什麼elem.getAttribute(「someAttribute」)不返回更新的值。Java Script中的getAttribute(attr)方法返回屬性的以前值
<body>
<input type="text" value="previousValue">
<script>
var input = document.body.children[0]
input.value = 'newValue'
alert(input.getAttribute('value')) // 'previousValue', not changed!
</script>
</body>
任何人都可以解釋一下嗎?
得到了清除。謝謝 – 2014-10-30 08:26:14
@ShoaibChikate這是TJ的另一個優秀帖子,它更深入地解釋了HTML屬性與DOM屬性:http://stackoverflow.com/a/5884994/1331430以下是對此特定行爲的更多技術解釋:http:// stackoverflow.com/a/11779426/1331430 – 2014-10-30 09:45:11
非常感謝。非常有用的鏈接 – 2014-10-30 10:12:05