Javascript相当于#include还是@import? [英] Javascript equivalent of #include or @import?

查看:61
本文介绍了Javascript相当于#include还是@import?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当然知道您可以使用< script src ="">< / script>在HTML

文档中包含javascript代码,你不想在

页面上溢出。


我我想知道是否有办法在* javascript中包含其他javascript代码* / b $ b代码....在C中包含#include,在Java中使用@import,

在Perl中使用/ require,在PHP等中包含()/ require()....


谢谢,

Weston


~ ==〜
http:// weston .canncentral.org /

weston8 [at] cann8central.org

(删除八个给我发电子邮件)


***通过开发人员发送的指南 http://www.developersdex.com ***

不要只是参加USENET ......获得奖励!

I know of course that you can use <script src=""></script> in an HTML
document to include javascript code you don''t want to spill all over the
page.

I''m wondering if there''s a way to include other pieces of javascript
code from *within* javascript.... a la #include in C, @import in Java,
use/require in Perl, include()/require() in PHP, etc....

Thanks,
Weston

~==~
http://weston.canncentral.org/
weston8[at]cann8central.org
(remove eights to email me)

*** Sent via Developersdex http://www.developersdex.com ***
Don''t just participate in USENET...get rewarded for it!

推荐答案

Weston C< west8on [在] cann8central.RemoveEights.org>写道:
Weston C <west8on[at]cann8central.RemoveEights.org> writes:
我当然知道你可以使用< script src ="">< / script>在HTML
文档中包含javascript代码,你不想在
页面上溢出。


不明白。你在谈论

<! - < script src =" ..."类型= QUOT;文本/ JavaScript的">< /脚本> - >



< script src =" ..." type =" text / javascript"><! - - >< / script>



第一个什么都不做,第二个没有我不需要评论。

我想知道是否有办法在* javascript中包含其他javascript代码* a la #include in C,@ import in Java,
在Perl中使用/ require,在PHP中包含()/ require()等等。
I know of course that you can use <script src=""></script> in an HTML
document to include javascript code you don''t want to spill all over the
page.
Not understood. Are you talking about
<!-- <script src="..." type="text/javascript"></script> -->
or
<script src="..." type="text/javascript"><!-- --></script>
?
The first does nothing, the second doesn''t need the comment.
I''m wondering if there''s a way to include other pieces of javascript
code from *within* javascript.... a la #include in C, @import in Java,
use/require in Perl, include()/require() in PHP, etc....




不在一般,不。如果你想在页面加载时加入它,你可以使用document.write写一个新的Javascript标签:


document.write( ''< script type =" text / javascript src =" ...">< / script>'');


页面加载后,它变得更难。有些浏览器允许你通过使用DOM方法向页面添加新的脚本标记来加载脚本,

或通过更改现有标记的src属性,或者通过更改现有脚本标记的

内容。

并非所有浏览器都了解所有或任何这些方法,但是,

所以它这不是什么可以依赖的。


/ L

-

Lasse Reichstein Nielsen - lr*@hotpop.com

DHTML死亡颜色:< URL:http://www.infimum.dk/HTML/rasterTriangleDOM。 html>

''没有判断的信仰只会降低精神神圣。''



Not in general, no. If you want to include it while the page is being
loaded, you can use document.write to write a new Javascript tag:

document.write(''<script type="text/javascript src="..."></script>'');

After the page has loaded, it becomes harder. Some browsers allow you
to load a script by adding a new script tag to the page using DOM methods,
or by changing the src attribute of an existing tag, or by changing the
content of an existing script tag.
Not all browsers understand all, or any, of these methods, though,
so it''s not something to depend on.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
''Faith without judgement merely degrades the spirit divine.''


在文章< vf ******* *** @ hotpop.com>,Lasse Reichstein Nielsen< lr*@hotpop.com>

写道:
In article <vf**********@hotpop.com>, Lasse Reichstein Nielsen <lr*@hotpop.com>
writes:
页面加载后,它变得更难。有些浏览器允许您通过使用DOM方法向页面添加新的脚本标记来加载脚本,或者通过更改现有标记的src属性,或者通过更改
内容来加载脚本。现有的脚本标签。
并非所有浏览器都能理解这些方法中的所有或任何一种,但是,
因此不能依赖它。
After the page has loaded, it becomes harder. Some browsers allow you
to load a script by adding a new script tag to the page using DOM methods,
or by changing the src attribute of an existing tag, or by changing the
content of an existing script tag.
Not all browsers understand all, or any, of these methods, though,
so it''s not something to depend on.



您知道一个浏览器不支持动态加载脚本

文件吗?除了O7?


< URL: http:// tinyurl.com/d25q >


我仍​​然在使用Opera时头脑无力,而无需使用

IFrames / Frames解决方案。但是对于任何不能处理上述URL中的

方法的浏览器的知识对我来说都是非常有用的。


-

Randy



Do you know of a browser that doesn''t support dynamically loading a script
file? Other than O7?

<URL: http://tinyurl.com/d25q >

I am still beating my head with Opera in general without resorting to an
IFrames/Frames solution. But knowledge of any browser that won''t handle the
methods in the above URL would be of great use to me.

--
Randy


hi ** ********* *@aol.com (HikksNotAtHome)写道:
hi************@aol.com (HikksNotAtHome) writes:
你知道一个浏览器不支持动态加载一个脚本
文件?除了O7?


我正在运行O7.5预览,它可以在那里工作。

我能做到:


var scr = document.createElement(" script");

scr.type =" text / javascript" ;;

document.body.appendChild(scr);

scr.src =" ../../ alert.js" ;; //提醒显示已加载的内容。


并更改脚本元素的文本:


document.getElementById(" idOfScriptElement")。text =" alert(''foo'')"


你只需要等待它才会被释放

广泛使用:)

< URL: http:// tinyurl.com/d25q >


(请写下这是一个链接。我通常不会按照

这样的链接,没有描述)。

我仍​​然在使用Opera时,不依赖于IFrames / Frames解决方案。但是知道任何浏览器都不会处理上述URL中的方法对我来说非常有用。
Do you know of a browser that doesn''t support dynamically loading a script
file? Other than O7?
I''m running O7.5 preview, and it works there.
I can do:

var scr = document.createElement("script");
scr.type="text/javascript";
document.body.appendChild(scr);
scr.src = "../../alert.js"; // alerts something to show it has loaded.

and also changing the text of a script element:

document.getElementById("idOfScriptElement").text = "alert(''foo'')"

You''ll just have to wait for it to be released before it becomes
widely used :)
<URL: http://tinyurl.com/d25q >
(Please write what it is a link to. I usually don''t follow links like
this without a description).
I am still beating my head with Opera in general without resorting
to an IFrames/Frames solution. But knowledge of any browser that
won''t handle the methods in the above URL would be of great use to
me.




那个文章看起来非常彻底。我不熟悉Netscape,Mozilla / Gecko,IE和Opera之外的浏览器

(但是那些,我已经安装了
17个版本:)。我会假设Netscape 2和3不会工作

,也不是早期的Operas,但我真的不在乎测试:)


/ L

-

Lasse Reichstein Nielsen - lr*@hotpop.com

DHTML死亡颜色:< URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>

''没有判断的信仰只会降低精神神圣。''



That article looks very thorough. I am not familiar with browsers
outside of Netscape, Mozilla/Gecko, IE and Opera (but of those, I have
17 versions installed :). I''ll assume that Netscape 2 and 3 won''t work
either, nor earlier Operas, but I don''t really care enough to test :)

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
''Faith without judgement merely degrades the spirit divine.''


这篇关于Javascript相当于#include还是@import?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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