关于JavaScript的基础的一个问题






gew
<br> var n=document.getElementById(&quot;name&quot;);<br> function vc()<br> {<br> var newWin = window.open();<br> with(newWin.document){</p> <pre><code> write(&quot;hello&quot;+n.value); write(&quot;&lt;/br&gt;&quot;); write(&quot;&lt;button onclick=&#39;self.close()&#39;&gt;close&lt;/button&gt;&quot;); } } &lt;/script&gt; &lt;/body&gt; </code></pre> <p></html><br> 为什么我在write前面加document.就显示不出文字了呢?</p>

这还有说吗,当然不行啊
你这个地方,就是把作用域设置成了newWin.document,自然里面的方法,属性都是属于newWin.document的了,newWin.document.document这是没有的啊
with([color=red]newWin.document[/color]){

write("hello"+n.value);
write("");
write("close");
}

如果你想加上document,就改写一下
with([color=red]newWin[/color]){

document.write("hello"+n.value);
document.write("");
document.write("close");
}

我看你写的那个,并不是加了document就显示不出文字吧,应该是加了document的话就在那张原来的页面上显示hello和close的button了吧,如果是write的话就应该在新打开的那张页面上有hello和close的button了吧,document是获取本页面的!所以加了document的话就是在本页面做改动!