This question already has an answer here:
这个问题在这里已有答案:
- Set the value of an input field 11 answers
设置输入字段11的值的答案
I have a function that creates a string and I would like for it to be displayed in a textbox on the page. I cannot understand why this does not work.
我有一个创建字符串的函数,我希望它显示在页面的文本框中。我无法理解为什么这不起作用。
HTML:
<input id="poNum" type="text" name="PO" id="PO" style="width: 310px;" readonly />
JS:
document.getElementById("poNum").innerHTML = number;
3 个解决方案
#1
0
document.getElementById("poNum").value = number;
InnerHTML is accessing... well, the actual inner html. Where as value is a attribute for inputs (selects, buttons, etc).
InnerHTML正在访问......好吧,实际的内部html。其中value是输入的属性(选择,按钮等)。
#2
0
Use document.getElementById("poNum").value = number;
使用document.getElementById(“poNum”)。value = number;
#3
0
<input>
elements have values, not inner HTML:
元素具有值,而不是内部HTML:
document.getElementById("poNum").value = number;
#1
0
document.getElementById("poNum").value = number;
InnerHTML is accessing... well, the actual inner html. Where as value is a attribute for inputs (selects, buttons, etc).
InnerHTML正在访问......好吧,实际的内部html。其中value是输入的属性(选择,按钮等)。
#2
0
Use document.getElementById("poNum").value = number;
使用document.getElementById(“poNum”)。value = number;
#3
0
<input>
elements have values, not inner HTML:
元素具有值,而不是内部HTML:
document.getElementById("poNum").value = number;