Javascript Chrome 中的 document.getElementById().innerText
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7714162/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
document.getElementById().innerText in Chrome
提问by strvanica
Quick Cross Browser JS question, when setting the value of a textbox:
Quick Cross Browser JS 问题,当设置文本框的值时:
document.getElementById("balanceText").innerText = "111";
and
和
document.getElementById("balanceText").value = "111";
Both Work grand in IE,
两者都在 IE 中工作,
But they will not work in Chrome, FF, Opera or Safari.
但它们不能在 Chrome、FF、Opera 或 Safari 中工作。
Is there an alternate method that will work in these browsers ?
是否有其他方法可以在这些浏览器中使用?
回答by Quentin
All else being equal document.getElementById("balanceText").value = "111";
works fine in every significant* browser that supports JS.
document.getElementById("balanceText").value = "111";
在所有支持 JS 的重要* 浏览器中,所有其他条件都相同。
Make sure that you have one, and only one, element with id="balanceText"
and that it actually has that as its idand not just the name.
确保您有一个且只有一个元素,id="balanceText"
并且它实际上将其作为id而不仅仅是name。
*
you don't care about NS 4 do you?
*
你不在乎 NS 4 是吗?