码迷,mamicode.com
首页 > 其他好文 > 详细

with语句和空语句

时间:2019-05-13 12:41:36      阅读:96      评论:0      收藏:0      [点我收藏+]

标签:dfs   使用   作用   gre   属性   作用域   ntb   order   color   

  with语句能够为一组语句创建缺省的对象,在一组语句中,任何不指定对象的属性引用都将被认为是缺省对象。

语法如下:

with(object){
     statements;  
}
<body>
    <div id="cc">sdfsdf</div>
    <script>
       document.getElementById("cc").style.background="red";
       document.getElementById("cc").style.border="1px solid green";

       //如果我们使用with语句就可以简略的写
       with(document.getElementById("cc").style){
           background="pink";
           border="10px solid black";

       }
    </script>
</body>

with语句能够破坏变量的作用域链,一般建议使用

with语句和空语句

标签:dfs   使用   作用   gre   属性   作用域   ntb   order   color   

原文地址:https://www.cnblogs.com/xiaowie/p/10855810.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!