Element.value和Element.getAttribute之间的差异(“value”) [英] Difference between Element.value and Element.getAttribute("value")

查看:68
本文介绍了Element.value和Element.getAttribute之间的差异(“value”)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想知道两者之间有什么区别。我注意到这两种方法有时会产生不同的结果。

解决方案

区别在于 element.value 是实时的,如果用户更改说明,则输入文本框,将反映出来,并向您显示新值。



getAttribute('value')仍将显示原始的 value =whateverWasHere值。



jsFiddle演示


I'm just wondering what the difference is between the two. I have noticed the two methods give different results at times.

解决方案

The difference is that element.value is real time and if a user changes let's say, a textbox input, it will reflect that, and show you the new value.

While getAttribute('value') will still show the original value="whateverWasHere" value.

jsFiddle DEMO

这篇关于Element.value和Element.getAttribute之间的差异(“value”)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆