原生js实现数据的双向绑定
需要了解的属性是原色js的Object.definePrototype(obj,pop,descript);
obj:被构造的对象
pop:被构造的对象的属性,创建对象或修改已有的对象
descript:修改的熟悉的描述
<!doctype html> <html> <head> <meta charset="utf-8"> <title>canvas粒子烟雾</title> </head> <body> <input id="aa" type="text" /> <span id="bb">{{test}}</span> <script> var obj = {}; Object.defineProperty(obj,'test',{ set(val) { document.querySelector('#aa').value = val; document.querySelector('#bb').innerHTML = val; } }) console.log(document.querySelector('#aa')); document.querySelector('#aa').onkeyup = function(e) { obj.test = e.target.value; } </script> </body> </html>