最佳答案
您需要有一个事件监听器来在用户输入某些输入时执行某些代码。
document.getElementById("myInput").addEventListener("input", function() {
// The input just changed. Do something with it.
// For example change the text in the div:
document.getElementById("myOutput").innerText = this.value;
});
<input type="text" id="myInput" />
<div id="myOutput"></div>
这是an example .
关于javascript - 如何根据用户输入在div中显示数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40365302/