其他分享
首页 > 其他分享> > proxy 第一遍

proxy 第一遍

作者:互联网

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>proxy第一遍</title>
  </head>
  <body>
    <input type="text" id="input" />
    <p id="show"></p>
    <script>
      let obj = {};
      const input = document.getElementById('input');
      const show = document.getElementById('show');
      let newObj = new Proxy(obj, {
        set(target, key, value) {
          if (key === 'text') {
            input.value = value;
            show.innerHTML = value;
          }
          return Reflect.set(target, key, value);
        },
        get(target, key) {
          return Reflect.get(target, key);
        }
      });
      input.addEventListener('keyup', function (e) {
        newObj.text = e.target.value;
      });
    </script>
  </body>
</html>

 

标签:第一遍,target,show,value,proxy,key,input
来源: https://www.cnblogs.com/pengxiangchong/p/16236967.html