document.write问题 [英] document.write issue

查看:87
本文介绍了document.write问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我有以下脚本:


--------------- -------------------------------------------------- ------------------

< script type =" text / javaScript">

<! -

document.write(''< div id = hello1> Hello1< / div>'');

document.write(''< div id = hello2 style =" display:none;">< script

src =" test.js">< \ / script>< / div>'') ;

// - >

< / script>


其中test.js包含一行:document。写(Hello2);

---------------------------------- -------------------------------------------------


目的是只显示第一个div并隐藏sencond div直到很晚

如果需要显示。

结果但是,显示了两个div内容。


如果我将脚本更改为:

--------------- ------------------------- -------------------------------------------

< script type =" text / javaScript">

<! -

document.write(''< div id = hello1> Hello1< / div>'');

document.write(''< div id = hello2

style =" display:none> document.write(" Hello2" ;);(< / div>'');

// - >

< / script>

- -------------------------------------------------- -------------------------------

工作正常。

如果我进一步改为:

------------------------------ -------------------------------------------------- ---

< script type =" text / javaScript">

<! -

document.write(' '< div id = hello1> Hello1< / div>'');

// - >

< / script>


< script type =" text / javaScript"> document.write(''< div id = hello2

style =" display:none >'');< / script>

< script type =" text / javaScript"> document.write(''< script

src =" test.js">< \ / script>'');< / script>

< script type =" text / javaScript"> document.write( ''< / div>'');< / script>

-------------------------- -------------------------------------------------- -------

它也可以正常使用。


非常感谢任何帮助。


Sean


Hi,

I have the following script:

-----------------------------------------------------------------------------------
<script type="text/javaScript">
<!--
document.write(''<div id=hello1>Hello1</div>'');
document.write(''<div id=hello2 style="display:none;"><script
src="test.js"><\/script></div>'');
//-->
</script>

where test.js contains one line: document.write("Hello2");
-----------------------------------------------------------------------------------

The intent is to only show the first div and hide the sencond div until late
to display if needed.
The result, however, shown both div contents.

If I change the script to:
-----------------------------------------------------------------------------------
<script type="text/javaScript">
<!--
document.write(''<div id=hello1>Hello1</div>'');
document.write(''<div id=hello2
style="display:none>document.write("Hello2");(</div>'');
//-->
</script>
-----------------------------------------------------------------------------------
It works fine.

If I further change it to:
-----------------------------------------------------------------------------------
<script type="text/javaScript">
<!--
document.write(''<div id=hello1>Hello1</div>'');
//-->
</script>

<script type="text/javaScript">document.write(''<div id=hello2
style="display:none>'');</script>
<script type="text/javaScript">document.write(''<script
src="test.js"><\/script>'');</script>
<script type="text/javaScript">document.write(''</div>'');</script>
-----------------------------------------------------------------------------------
it also works fine.

Any help is highly appreciated.

Sean


推荐答案

在文章< msAee.1237937
In article <msAee.1237937


6l。 256275 @ pd7tw2no>, sn********@hotmail.com

启发我们...
6l.256275@pd7tw2no>, sn********@hotmail.com
enlightened us with...


我有以下脚本:
Hi,

I have the following script:




Out of好奇,为什么你使用相当过时的document.write来

添加新的DOM元素?

Do y你需要支持旧浏览器吗?


你可以用DOM方法添加脚本元素和DIV。


那说,我似乎记得一个document.write和写标签的问题

"< / script>"

我认为你需要拆分它,比如

document.write("< / scr" +" ipt>");

关于解析器将其解释为真实< / script> ...的事情?


-

-

~kaeli~

当两个自我主义者相遇时,它是一个我是一个人。
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace



Out of curiousity, why are you using the rather outdated document.write to
add new DOM elements?
Do you need to support old browsers?

You can add script elements and DIVs with DOM methods.

That said, I seem to recall a problem with document.write and writing the tag
"</script>"
I think you need to split it, like
document.write("</scr"+"ipt>");
Something about the parser interpreting it as a real </script>...?

--
--
~kaeli~
When two egotists meet, it''s an I for an I.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace


kaeli写道:
kaeli wrote:
文章< msAee.1237937
In article <msAee.1237937


这篇关于document.write问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆