Ели*_*ков 3 html javascript html5 function ecmascript-6
为什么我不能将输入值插入另一个输入?以下示例不起作用:
document.getElementById("input").oninput = () => {
const input = document.getElementById('input');
const output = document.getElementById('output');
// Trying to insert text into 'output'.
output.innerText = input.value;
};Run Code Online (Sandbox Code Playgroud)
<input id="input" placeholder="enter value of temperature" />
<br>
<input id="output" />Run Code Online (Sandbox Code Playgroud)
谢谢!
您应该使用.value而不是.innerText将值设置为输入元素,如:
output.value = input.value;
Run Code Online (Sandbox Code Playgroud)
document.getElementById("input").oninput = () => {
const input = document.getElementById('input');
const output = document.getElementById('output');
output.value = input.value;
};Run Code Online (Sandbox Code Playgroud)
<input id="input" placeholder="enter value of temperature" />
<br>
<input id="output" />Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
208 次 |
| 最近记录: |