欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

JavaScript 我这样写with 格式有什么问题吗?为什么不行?

程序员文章站 2022-05-17 14:05:23
...
正常运行的结果:
aobj.href="abcdefghi";
aobj.target="_blank";
aobj.style.backgroundColor='yellow';
aobj.style.float= "left"; 
aobj.style.overflow="hidden";
aobj.appendChild(img);

用了with之后不能运行的结果:

wiht(aobj)
{
href="abcdefghi";
target="_blank";
style.backgroundColor='yellow';
style.float= "left"; 
style.overflow="hidden";
appendChild(img);
}

哪里有问题,还望指教!

直接帮我改了我再摸索吧,谢谢了!

回复内容:

正常运行的结果:

aobj.href="abcdefghi";
aobj.target="_blank";
aobj.style.backgroundColor='yellow';
aobj.style.float= "left"; 
aobj.style.overflow="hidden";
aobj.appendChild(img);

用了with之后不能运行的结果:

wiht(aobj)
{
href="abcdefghi";
target="_blank";
style.backgroundColor='yellow';
style.float= "left"; 
style.overflow="hidden";
appendChild(img);
}

哪里有问题,还望指教!

直接帮我改了我再摸索吧,谢谢了!

wiht拼写错误

aobj = {
    href: null,
    target: null,
    style: {},
    appendChild: null
};
with(aobj) {
    href="abcdefghi";
    target="_blank";
    style.backgroundColor='yellow';
    style.float= "left"; 
    style.overflow="hidden";
    appendChild(img);
}

with里面用不了没定义的属性