如何通过JavaScript更改h:outputText值?

Pet*_*ter 6 javascript jsf

我已经用2 inputText进行了测试,例如它运行良好

var tdate = document.getElementById('txtDate');    //h:inputText
var tdt = document.getElementById('txtDateTime');  //h:inputText

tdate.onchange = function(){
  tdt.value = tdate.value;
};
Run Code Online (Sandbox Code Playgroud)

如何更改"tdt"的值 - h:outputText?

var tdate = document.getElementById('txtDate');    //h:inputText
var tdt = document.getElementById('txtDateTime');  //h:outputText
Run Code Online (Sandbox Code Playgroud)

Bal*_*usC 3

查看生成的 HTML 源代码。在浏览器中右键单击页面并查看源代码。您将看到渲染<h:outputText>了一个 HTML<span>元素,其值位于其主体中。要更改 JavaScript 中 a 的主体,<span>您需要操作innerHTML.

tdt.innerHTML = "new value";
Run Code Online (Sandbox Code Playgroud)