ret log 实现 inner input innerhtml 数据 script value
实现代码:
- <input type="text" id="foo">
- <button id="btn">提交</button>
- <button id="btn1">设置</button>
- <div>输入框的内容:<input type="text" id="xianshi"></div>
- <script>
- var user = {};
- var foo = document.getElementById("foo");
- var xianshi = document.getElementById("xianshi");
- Object.defineProperty(user, ‘name‘, {
- get: function () {
- return document.getElementById(‘foo‘).value;
- },
- set: function (newValue) {
- console.log(newValue);
- document.getElementById(‘foo‘).value = newValue;
- },
- configurable: true
- });
- foo.oninput = function () {
- xianshi.value = user.name;
- }
- xianshi.oninput = function () {
- user.name = xianshi.value;
- xianshi.innerHTML = user.name;
- }
- </script>
使用js实现一个简单的数据双向绑定
ret log 实现 inner input innerhtml 数据 script value
原文:http://www.cnblogs.com/zjy1017/p/7911964.html
来源: http://www.bubuko.com/infodetail-2410639.html