且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

即时添加JavaScript

更新时间:2023-12-05 22:02:16

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.