如何通过 JavaScript 更改 h:outputText 值?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10844349/
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
How to change h:outputText value by JavaScript?
提问by Peter
I already tested with 2 inputText, It runs well for example
我已经用 2 个 inputText 进行了测试,例如它运行良好
var tdate = document.getElementById('txtDate'); //h:inputText
var tdt = document.getElementById('txtDateTime'); //h:inputText
tdate.onchange = function(){
tdt.value = tdate.value;
};
How can I change the value of " tdt " - h:outputText?
如何更改“tdt”-h:outputText 的值?
var tdate = document.getElementById('txtDate'); //h:inputText
var tdt = document.getElementById('txtDateTime'); //h:outputText
采纳答案by BalusC
Look in the generated HTML source. Rightclick page in browser and view source. You'll see that the <h:outputText>
renders a HTML <span>
element with the value in its body. To alter the body of a <span>
in JavaScript you need to manipulate the innerHTML
.
查看生成的 HTML 源代码。在浏览器中右键单击页面并查看源代码。您将看到<h:outputText>
渲染了一个 HTML<span>
元素,其正文中包含该值。要<span>
在 JavaScript 中更改 a 的主体,您需要操作innerHTML
.
tdt.innerHTML = "new value";