1.看例子

<script language="javascript">  
function Lakers() {  
       this.name = "kobe bryant";  
       this.age = "28";  
       this.gender = "boy";  
}  
var people=new Lakers();  
with(people)  
{  
       var str = "姓名: " + name + "<br>";  
       str += "年龄:" + age + "<br>";  
       str += "性别:" + gender;  
       document.write(str);  
}  
</script>  

代码执行效果如下:

姓名: kobe bryant
年龄:28
性别:boy

2.系统对象

     <script type="text/javascript">
    
        with(location){
            var hostName = hostname;    
            var url = href;
        }
        alert(hostName);
        alert(url);

    </script>

执行结果:

localhost
http://localhost/xxx.html

相关文章:

  • 2021-06-02
  • 2021-06-17
  • 2021-09-29
  • 2021-09-12
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-16
  • 2021-08-02
  • 2022-12-23
  • 2022-12-23
  • 2021-08-06
  • 2022-03-03
相关资源
相似解决方案