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>

posted @ 2019-10-15 15:58  小丶鱼  阅读(3255)  评论(0编辑  收藏  举报