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

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

WBOY
WBOYOriginal
2016-06-06 20:12:25837browse

正常运行的结果:

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

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

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

哪里有问题,还望指教!

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

回复内容:

正常运行的结果:

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

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

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

哪里有问题,还望指教!

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

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>

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

Statement:
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