双向绑定的极简实现
<input id="a" type="text" /> <span id="b"></span>
var obj = {}; Object.defineProperty(obj,'txt',{ set:function(val){ document.getElementById('a').value = val; document.getElementById('b').innerHTML = val; } }) document.getElementById('a').addEventListener('input',function(e){ obj.txt = e.target.value; });