标签:val lis listen style element doc prope meta tar
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>双向数据绑定</title>
</head>
<body>
<div id="all">
<input type="text" id="txt">
<p id="show-txt"></p>
</div>
<script>
var obj={};
var txt = document.getElementById("txt");
var show_txt = document.getElementById("show-txt");
Object.defineProperty(obj,‘txt‘,{
get : function () {
return obj;
},
set : function (value) {
show_txt.innerHTML = value;
}
});
txt.addEventListener(‘keyup‘,function (e) {
obj.txt = e.target.value;
});
</script>
</body>
</html>
标签:val lis listen style element doc prope meta tar
原文地址:https://www.cnblogs.com/blogs-zong/p/12095887.html