在JavaScript中将文本输出到输入字段
试图按下在输入字段中输出文本的按钮。功能是在按下时将文本“x”输出到输入字段,该字段设置为只读。只允许使用js和html。以下是迄今为止我在HTML和js中获得的信息:在JavaScript中将文本输出到输入字段,javascript,html,Javascript,Html,试图按下在输入字段中输出文本的按钮。功能是在按下时将文本“x”输出到输入字段,该字段设置为只读。只允许使用js和html。以下是迄今为止我在HTML和js中获得的信息: <button id="button4" onclick="output()">Hokus Pokus</button> <input id="printoutput" readonly="true" type="text"> 为什么不起作用?您需要设置输入的值,而不是内部html d
<button id="button4" onclick="output()">Hokus Pokus</button>
<input id="printoutput" readonly="true" type="text">
为什么不起作用?您需要设置输入的值,而不是内部html
document.getElementById(“打印输出”).value=“x”代码>
Hokus Pokus
像这样做,它就像一个符咒:
函数输出(){
document.getElementById(“打印输出”).value=“x”;
}
Hokus Pokus
已修复。他这样做:
function output() {
document.getElementById("printoutput").innerHTML = "x";
}
何时应该:
function output() {
document.getElementById("printoutput").value = "x";
}
哦,天哪,这显然是我的疏忽。谢谢
function output() {
document.getElementById("printoutput").value = "x";
}