一个对象 有多个属性 或者有多个方法 需要操作 用with
如:
<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 的
用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>