JavaScript简单的数据绑定
addEventListener()用来监听输入值改变:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<input type="text" id="input1">
<input type="text" id="input2">
<script>
//addEventListener在文本中输入数据 触发回调函数
input1.addEventListener('input',function(){
input2.value = this.value;
})
input2.addEventListener('input',function(){
input1.value = this.value;
})
</script>
</body>
</html>
执行结果: