<!DOCTYPE html>
<html>
<head><meta charset="utf-8"></head>
<body>
<input type="text" oninput="click1(event)">
<div id="aaa"></div>
</body>
<script type="text/javascript">
let content = '和输入框双向绑定';
let a = {
b: content,
}
document.getElementById('aaa').innerHTML = a.b
Object.defineProperty(a, 'b', {
get(){
console.log('取数据操作');
return content
},
set(newValue){
console.log('存数据操作');
content = newValue
document.getElementById('aaa').innerHTML = content
}
})
function click1(event){
a.b = event.target.value
}
</script>
</html>
06-13
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交