为什么输入的value属性没有变化? [英] Why doesn't the value attribute of the input change?
本文介绍了为什么输入的value属性没有变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
好吧,我有这个代码:
然后我做了一些会调用这个函数的事件:
chooseSite = function () {var url = "/main/Ajax/GetSiteDetail?"+"&cid=" + 转义(idSite);var ajx = sendAJAX(url, true);ajx.onreadystatechange = 函数 () {如果(ajx.readyState == 4){var 结果 = ajx.responseText;结果 = "顶部";document.getElementById("CI.SiteName").value = result;}}}
在浏览器中它变成了TOP"但是当我用firebug检查元素时,INPUT的VALUE属性仍然是",没有改变.
解决方案
value
attribute 与实际值不同步;这就是 value
property 的用途.
这不是问题,因为您永远不会使用 .getAttribute('value')
而是使用属性 .value
来访问当前值.>
Well I have this code in view:
<input id="CI.SiteName" type="text" value="" name="@@CI.SiteName" disabled="">
and then I doing some event that would call this function:
chooseSite = function () {
var url = "/main/Ajax/GetSiteDetail?" +
"&cid=" + escape(idSite);
var ajx = sendAJAX(url, true);
ajx.onreadystatechange = function () {
if (ajx.readyState == 4) {
var result = ajx.responseText;
result = "TOP";
document.getElementById("CI.SiteName").value = result;
}
}
}
in browser it changed to "TOP" but when I inspect element with firebug, the VALUE attribute of INPUT still "", not changed.
解决方案
The value
attribute is not synced with the actual value; that's what the value
property is for.
This is not a problem though since you'll never use .getAttribute('value')
but use the property .value
to access the current value.
这篇关于为什么输入的value属性没有变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文