zoukankan      html  css  js  c++  java
  • javascript的with

    当你有一个对象的多个属性或者方法需要操作时,就可以使用with

    比如
    <body>
    test
    <script type="text/javascript">
    var o=document.createElement("div");
    with(o){
    style.cursor="pointer";
    style.zIndex="100";
    innerHTML="aaaa";
    }
    document.body.appendChild(o);
    </script>
    </body>
    上面的代码相当于

    <body>
    test
    <script type="text/javascript">
    var o=document.createElement("div");
    o.style.cursor="pointer";
    o.style.zIndex="100";
    o.innerHTML="aaaa";
    document.body.appendChild(o);
    </script>
    </body>

    所以with 用于简化 代码 操作。
  • 相关阅读:
    【leetcode】二叉搜索树的最近公共祖先
    052-12
    052-11
    052-10
    052-9
    052-8
    052-6
    052-5
    052-3
    052-2
  • 原文地址:https://www.cnblogs.com/yanni/p/3262127.html
Copyright © 2011-2022 走看看