即时添加JavaScript [英] add javascript on the fly

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

问题描述

大家好。正如我的帖子所说,我想在我的页面上添加javascript

the fly。例如


page1.html


< html>

< head>

< script type =''text / javascript''src =''controlador.js''>< / script>


< title> ... < / title>

< / head>

< body>

......

< / body>

< / html>


现在加载页面时,根据某些用户的操作,我'd

喜欢添加一个新的脚本,比如这个。


page1.html


< html> ;

< head>

< script type =''text / javascript''src =''controlador.js''>< / script>

< script type =''text / javascript''src =''new-file-just-added.js''>< / script>


< title> ...< / title>

< / head>

< body>

.. ....

< / body>

< / html>


对了现在我正在这样做。


document.write("< script type =''text / javascript''src =''new-file-just-

added.js''''>< / script>");


显然这不能正常工作,因为,我想,在那方式

所有内容都被删除。


希望你能帮忙。谢谢

Hi every body. as my post says, i want to add javascript to my page on
the fly. for example

page1.html

<html>
<head>
<script type=''text/javascript''src=''controlador.js''></script>

<title>...</title>
</head>
<body>
......
</body>
</html>

now when the page has been loaded, acording some user''s actions, i''d
like to add a new script, like this.

page1.html

<html>
<head>
<script type=''text/javascript''src=''controlador.js''></script>
<script type=''text/javascript''src=''new-file-just-added.js''></script>

<title>...</title>
</head>
<body>
......
</body>
</html>

right now i''m doing this.

document.write("<script type=''text/javascript''src=''new-file-just-
added.js''''></script>");

obviusly this is not working properly, because, i think, in that way
all the content is erased.

hope you can helpme. thanks

推荐答案

ojvm写道:
ojvm wrote:

现在当页面有已加载,根据某些用户的

操作,我想添加一个新脚本,
now when the page has been loaded, acording some user''s
actions, i''d like to add a new script,



[... ]

[...]


现在我正在这样做。


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

src =''new-file-just-added.js''''>< / script>");


显然这不能正常工作,因为,我认为,

就这样所有内容都被删除了。


希望你能帮忙。谢谢
right now i''m doing this.

document.write("<script type=''text/javascript''
src=''new-file-just-added.js''''></script>");

obviusly this is not working properly, because, i think,
in that way all the content is erased.

hope you can helpme. thanks



var sc = document.createElement(''script'')

sc.type =''text / javascript''

sc.src =''new-file-just-added.js''

document.getElementsByTagName(''head'')[0] .appendChild(sc)


在访问file.js的内容之前,首先应确保

它已满载。
http://groups.google.com/group /comp....7fc1b1393136b9

希望这会有所帮助,


-

Bart

var sc = document.createElement(''script'')
sc.type = ''text/javascript''
sc.src = ''new-file-just-added.js''
document.getElementsByTagName(''head'')[0].appendChild(sc)

Before accessing the content of of file.js, you should first make sure
that it''s fully loaded.

http://groups.google.com/group/comp....7fc1b1393136b9

Hope this helps,

--
Bart


3月13日上午5:20,ojvm < yomerosoy2005-foros ... @ yahoo.comwrote:
On Mar 13, 5:20 am, "ojvm" <yomerosoy2005-foros...@yahoo.comwrote:

大家好。正如我的帖子所说,我想在我的页面上添加javascript

the fly。例如
Hi every body. as my post says, i want to add javascript to my page on
the fly. for example



< FAQENTRY>


这个问题似乎每周被问过一次过去的问题/>
年份 - 常见问题解答条目?


< /常见问题>


-

Rob

<FAQENTRY>

This question seems to have been asked about once a week for the past
year - time for an FAQ entry?

</FAQENTRY>

--
Rob


2007年3月12日星期一12:20:07 -0700,ojvm写道:
On Mon, 12 Mar 2007 12:20:07 -0700, ojvm wrote:

大家好。正如我的帖子所说,我想在我的页面上添加javascript

the fly。例如
Hi every body. as my post says, i want to add javascript to my page on
the fly. for example



服务器端包含在页面下载时发生...所以,你

不能这样做。


调查AJAX。

Server-side includes happen at the time the page is downloaded... so, you
can''t do that.

Look into AJAX.


这篇关于即时添加JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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