Home > Web Front-end > JS Tutorial > Front-end js two-way data binding

Front-end js two-way data binding

小云云
Release: 2017-12-08 16:16:57
Original
2009 people have browsed it

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: &#39;Hello&#39;
    };
    Object.defineProperty(obj, &#39;infoBind&#39;, {
        get: function () {
            return this.seeYou;
        },
        set: function (newValue) {
            document.getElementById(&#39;infoShow&#39;).innerText = newValue;
            document.getElementsByName(&#39;infoInsert&#39;)[0].value = newValue;
        }
    });
    document.getElementsByName(&#39;infoInsert&#39;)[0].addEventListener(&#39;keyup&#39;, function () {
        obj.infoBind = this.value;
    });
</script>
</body>
</html>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template