将一个外部JS文件直接包含在另一个中 [英] Including one external JS file directly into another

查看:53
本文介绍了将一个外部JS文件直接包含在另一个中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方法将一个JS文件直接加载到另一个,

*,而不必动态写入< scripttags。


有没有我可以使用

单个< scripttag调用一个外部JS文件的方法,但是将外部JS文件插入到ITSELF

其他五个内容中?


类似于:


/ * start external.js * /

import(" / js / script1 .js")

import(" /js/script2.js")

import(" /js/script3.js")

import(" /js/script4.js")

import(" /js/script5.js")

/ * end external.js * /


TIA

... Geshel

-

******* ******************************************* ******* ************

我的回复电子邮件地址是一个自动监控的垃圾邮件蜜罐。

除非你发送电子邮件希望被报道为垃圾邮件发送者。

请将所有电子邮件发送到我姓氏dot org的名字,然后用

作为NEO GESHELA的新闻报道? (全部大写)。

************************************* ************* *******************

I am seeking a method to load one JS file directly into another,
*without* having to dynamically write <scripttags.

Is there any method whereby I can call only one external JS file using a
single <scripttag, but have that external JS file insert into ITSELF
the contents of five others?

Something like:

/*start external.js*/
import ("/js/script1.js")
import ("/js/script2.js")
import ("/js/script3.js")
import ("/js/script4.js")
import ("/js/script5.js")
/*end external.js*/

TIA
...Geshel
--
************************************************** *******************
My return e-mail address is an automatically monitored spam honeypot.
Do not send e-mail there unless you wish to be reported as a spammer.
Please send all e-mail to my first name at my last name dot org, with
a subject-line of a??NEWSGROUP REPLY FOR NEO GESHELa?? (all uppercase).
************************************************** *******************

推荐答案

" Neo Geshel" < go **** @ geshel.orgwrote in message news:45 ************** @ geshel.org ...
"Neo Geshel" <go****@geshel.orgwrote in message news:45**************@geshel.org...

我正在寻找一种方法将一个JS文件直接加载到另一个,*没有*必须

动态写入< scripttags。
I am seeking a method to load one JS file directly into another, *without* having to
dynamically write <scripttags.


是否有任何方法可以使用单个< script>

标记只调用一个外部JS文件,但是有外部JS文件将其他五个内容插入ITSELF?
Is there any method whereby I can call only one external JS file using a single <script>
tag, but have that external JS file insert into ITSELF the contents of five others?



基于Hunlock的可爱小片段:

http://www.hunlock.com/blogs/Howto_D...script_And_CSS


我写道:


函数embed_scripts()

{

var arg_obj = String(arguments [0]);

var arg =(arguments.length == 1)? arg_obj.split('',''):参数;

var head_obj = document.getElementsByTagName(''head'')[0];

for(var i = 0; i< arg.length; i ++)

{

var script_obj = document.createElement(''script'');

script_obj.type =''text / javascript'';

script_obj.src = arg [i] +''。js'';

head_obj.appendChild(script_obj );

}

}


它可以接受一个数组:


var _scripts = [''script1'',''script2''];

window.onload = embed_scripts(_scripts);


... 。或以逗号分隔的参数列表:


window.onload = embed_script(''script1'',''script2'');


现在,仅仅因为它对我来说完美无缺并不意味着它是防弹的。我可能没有

测试了所有情况,或者它可能是巧合的。


有一点可以肯定,它没有试图检查是否''script1''是一个有效的

文件。


让我们看看谁猛击我的头撞墙。 * grin *


-Lost

Based on Hunlock''s lovely little snippet:

http://www.hunlock.com/blogs/Howto_D...script_And_CSS

I wrote:

function embed_scripts()
{
var arg_obj = String(arguments[0]);
var arg = (arguments.length == 1) ? arg_obj.split('','') : arguments;
var head_obj = document.getElementsByTagName(''head'')[0];
for (var i = 0; i < arg.length; i++)
{
var script_obj = document.createElement(''script'');
script_obj.type = ''text/javascript'';
script_obj.src = arg[i] + ''.js'';
head_obj.appendChild(script_obj);
}
}

It can accept either an array:

var _scripts = [''script1'', ''script2''];
window.onload = embed_scripts(_scripts);

....or a comma-separated list of arguments:

window.onload = embed_script(''script1'', ''script2'');

Now, just because it worked flawlessly for me does not mean it is bulletproof. I may not
have tested all situations or it could be coincidental that it works.

One thing for certain, it makes no attempt to check whether or not ''script1'' is a valid
file.

Let''s see who "slams my head against the wall." *grin*

-Lost


" -Lost" < sp **************** @ REMOVEMEcomcast.net写在留言中

新闻:9q ************** ****************@comcast.com。 ..


< snip previous code>
"-Lost" <sp****************@REMOVEMEcomcast.netwrote in message
news:9q******************************@comcast.com. ..

<snip previous code>

window.onload = embed_script(''script1'','' SCRIPT2 '');
window.onload = embed_script(''script1'', ''script2'');



我在这一行的函数名末尾忘了''s'。


< snip> ;


-Lost

I forgot the ''s'' at the end of the function name on this line.

<snip>

-Lost


2月3日,1:39 pm,-Lost < spam_ninjaREMOV ... @ REMOVEMEcomcast.net>

写道:
On Feb 3, 1:39 pm, "-Lost" <spam_ninjaREMOV...@REMOVEMEcomcast.net>
wrote:

" Neo Geshel" < got ... @ geshel.orgwrote in messagenews:45 ************** @ geshel.org ...

我正在寻找一种加载方法一个JS文件直接进入另一个,*没有*必须

动态写< scripttags。

是否有任何方法可以使用单个调用一个外部JS文件< script>

标签,但是有外部JS文件将其他五个内容插入ITSELF吗?
"Neo Geshel" <got...@geshel.orgwrote in messagenews:45**************@geshel.org...
I am seeking a method to load one JS file directly into another, *without* having to
dynamically write <scripttags.
Is there any method whereby I can call only one external JS file using a single <script>
tag, but have that external JS file insert into ITSELF the contents of five others?



基于Hunlock的可爱小片段:

http://www.hunlock.com/blogs/Howto_D...script_And_CSS



[.. 。$

[...]


让我们看看谁猛击我的头撞墙。 * grin *
Let''s see who "slams my head against the wall." *grin*



一个小小的研究,线程createTextNode和IE7:


< URL: http://groups.google.com.au/group/comp。 lang.javascript /

browse_frm / thread / 7e23f42490c301de / 3441a1cc21869a10?

lnk = gst& q = createTextNode + IE + Randy + Web& rnum = 1& hl = en#3441a1cc21869a10>


-

Rob

A little research, thread "createTextNode and IE7":

<URL: http://groups.google.com.au/group/comp.lang.javascript/
browse_frm/thread/7e23f42490c301de/3441a1cc21869a10?
lnk=gst&q=createTextNode+IE+Randy+Web&rnum=1&hl=en #3441a1cc21869a10 >

--
Rob


这篇关于将一个外部JS文件直接包含在另一个中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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