Home > Backend Development > PHP Tutorial > JavaScript 我这样写with 格式有什么问题吗?为什么不行?

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

WBOY
Release: 2016-06-06 20:12:25
Original
839 people have browsed it

正常运行的结果:

<code>aobj.href="abcdefghi";
aobj.target="_blank";
aobj.style.backgroundColor='yellow';
aobj.style.float= "left"; 
aobj.style.overflow="hidden";
aobj.appendChild(img);</code>
Copy after login
Copy after login

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

<code>wiht(aobj)
{
href="abcdefghi";
target="_blank";
style.backgroundColor='yellow';
style.float= "left"; 
style.overflow="hidden";
appendChild(img);
}
</code>
Copy after login
Copy after login

哪里有问题,还望指教!

<code>直接帮我改了我再摸索吧,谢谢了!</code>
Copy after login
Copy after login

回复内容:

正常运行的结果:

<code>aobj.href="abcdefghi";
aobj.target="_blank";
aobj.style.backgroundColor='yellow';
aobj.style.float= "left"; 
aobj.style.overflow="hidden";
aobj.appendChild(img);</code>
Copy after login
Copy after login

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

<code>wiht(aobj)
{
href="abcdefghi";
target="_blank";
style.backgroundColor='yellow';
style.float= "left"; 
style.overflow="hidden";
appendChild(img);
}
</code>
Copy after login
Copy after login

哪里有问题,还望指教!

<code>直接帮我改了我再摸索吧,谢谢了!</code>
Copy after login
Copy after login

wiht拼写错误

<code class="javascript">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);
}</code>
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template