js实现数据绑定

  

<!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>

原文地址:https://www.cnblogs.com/yuxiaoge/p/11678231.html