<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<!-- oninput方法在输入框内容发生变化时触发 -->
<p id="p"></p>
<input type="text" id="txt" oninput="watch()">
</body>
<script>
var txt = document.getElementById('txt');
var ptxt = document.getElementById('p');
function watch() {
ptxt.innerHTML=txt.value;
console.log(txt.value)
}
</script>
</html>