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

正常运行的结果:

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);
}

哪里有问题,还望指教!

直接帮我改了我再摸索吧,谢谢了!
阅读 2.4k
2 个回答

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里面用不了没定义的属性

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题