<!DOCTYPE html> <html> <head> <title>vue-双向数据绑定的简单实现</title> </head> <body> <input type="text" name="" id="inputText"> <span id=‘textSpan‘></span> <script type="text/javascript"> let obj = {}, inputText = document.querySelector(‘#inputText‘), textSpan = document.querySelector(‘#textSpan‘) Object.defineProperty(obj, ‘foo‘, { set: function (newValue) { inputText.value = newValue textSpan.innerHTML = newValue } }) inputText.addEventListener(‘keyup‘, function (e) { obj.foo = e.target.value }) </script> </body> </html>
原文地址:https://www.cnblogs.com/maggie-pan/p/10025803.html
时间: 2024-11-09 06:07:33