Home > Article > Web Front-end > Front-end js two-way data binding
In this article, we will share with you the front-end js two-way data binding, hoping it will be helpful to everyone.
<html> <head> <title>textBind</title> </head> <body> <input type="text" name="infoInsert"> <p id="infoShow"></p> <script type="text/javascript"> var obj = { seeYou: 'Hello' }; Object.defineProperty(obj, 'infoBind', { get: function () { return this.seeYou; }, set: function (newValue) { document.getElementById('infoShow').innerText = newValue; document.getElementsByName('infoInsert')[0].value = newValue; } }); document.getElementsByName('infoInsert')[0].addEventListener('keyup', function () { obj.infoBind = this.value; }); </script> </body> </html>
Through the above code, it is not difficult to see that the underlying implementation principle of two-way data binding used in the framework is implemented through the defineProperty attribute in ES5.
Related recommendations:
JS method to implement two-way data binding
react.js parent-child component data binding real-time Communication example display
AngularJS two-way data binding detailed simple example
The above is the detailed content of Front-end js two-way data binding. For more information, please follow other related articles on the PHP Chinese website!