语法格式:
  with(obj){}
  obj指明了语句组中对象缺省时的参考对象,就是代表该语句块中的默认作用域为obj。

<html>
<head>
    <title></title>
    <meta charset="utf-8"/>
    <script type="text/javascript">
      function test(){
        var obj=document.getElementById("test");
        obj.className="red";
        obj.value="not use with";
      }
      function testWith(){
        var a=document.getElementById("test");
        with(a){
            value="using  with";
            className="blue";
        }
      }
    </script>
    
    <style type="text/css"> 
    .red{background:red;color:#ffffff} 
    .blue{background:blue;color:yellow} 
    </style> 

</head>
<body>
    <input /> 
    <input type="button" value="Changed" onclick="test()"/> 
    <input type="button" value="withChanged" onclick="testWith()"/> 
</body>
</html>

 

相关文章:

  • 2021-10-18
  • 2021-08-07
  • 2022-12-23
  • 2021-08-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-03-03
  • 2021-06-02
  • 2021-09-28
  • 2021-11-22
  • 2022-12-23
相关资源
相似解决方案