作业帮 > 综合 > 作业

javascript的with表示什么?

来源:学生作业帮 编辑:搜搜考试网作业帮 分类:综合作业 时间:2024/06/16 03:40:30
javascript的with表示什么?
javascript的with表示什么?
当你有一个对象的多个属性或者方法需要操作时,就可以使用with
比如

test

var o=document.createElement("div");
with(o){
style.cursor="pointer";
style.zIndex="100";
innerHTML="aaaa";
}
document.body.appendChild(o);

上面的代码相当于

test

var o=document.createElement("div");
o.style.cursor="pointer";
o.style.zIndex="100";
o.innerHTML="aaaa";
document.body.appendChild(o);

所以with 用于简化 代码 操作.