原生js實現數據的雙向綁定html
須要瞭解的屬性是原色js的Object.definePrototype(obj,pop,descript);canvas
obj:被構造的對象spa
pop:被構造的對象的屬性,建立對象或修改已有的對象雙向綁定
descript:修改的熟悉的描述code
<!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>