当元素在 HTML 中获得用户输入时执行脚本?
使用
示例
<!DOCTYPE html>
<html>
<body>
<p>Write your name below:</p>
<input type = "text" id = "myid" oninput="display()">
<p id="test"></p>
<script>
function display() {
var p = document.getElementById("myid").value;
document.getElementById("test").innerHTML = "Your answer is " + p;
}
</script>
</body>
</html>
广告