原生js双向数据绑定
2018-11-15 本文已影响0人
uncleT
<input type="text" id="aa"/>
<span id="bb">事件</span>
var obj = {};
Object.defineProperty(obj,'hello',{
set:function(val){
document.getElementById('bb').innerHTML = val;
document.getElementById('aa').value = val;
}
});
document.getElementById('aa').onkeyup = function(e){
obj.hello = e.target.value;
};
obj.hello = "";