简体   繁体   English

使用ExtJ时如何包括外部javascript文件?

[英]How to include an external javascript file when using ExtJs?

I'm using ExtJs 4.2.2 and included all necessary js and css files, and my codes work just fine, ONLY IF I write my code into script tags within my html file. 我正在使用ExtJs 4.2.2,并包括所有必要的js和css文件,并且我的代码工作正常,仅当我将代码写入html文件中的脚本标签中时。 When I try to put these code into another file with .js extension and include it between head tags properly, it returns nothing. 当我尝试将这些代码放入扩展名为.js的另一个文件中,并将其正确包含在head标签之间时,它什么也不返回。 I'm sure I've included my js file properly because when I fill it with standard js codes, I get results. 我确定我已经正确包含了我的js文件,因为当我用标准js代码填充它时,就会得到结果。 But with ExtJS syntax, the same code which return results within script tags, returns nothing. 但是,使用ExtJS语法,返回脚本标记内结果的相同代码将不返回任何内容。 How? 怎么样? Do I miss something? 我想念什么吗?

The following two are equivalent. 以下两个是等效的。 If one works, the others work, too, regardless of what js code you use: 如果一个可行,那么不管您使用哪种js代码,其他的也都可行:

(Ex 1.) (例1.)

<html><head>
<script>//your js code here</script>
</head><body>
</body></html>

and

(Ex 2.) (例2)。

<html><head>
<script src="jscode.js"></script>
</head><body>
</body></html>

where jscode.js contains jscode.js包含的位置

// your js code here

Furthermore, the following two are equivalent: 此外,以下两个是等效的:

(Ex 3.) (例3.)

<html><head>
</head><body>
<script>//your js code here</script>
</body></html>

and

(Ex 4.) (例4.)

<html><head>
</head><body>
<script src="jscode.js"></script>
</body></html>

NOTHING will change in behaviour. 什么都不会改变行为。

I think (but you didnt post ANY code at all, so it's jsut guessing) that you had Example 3 working, but changed to Example 2. But only 3 and 4 are equivalent! 我认为(但您根本没有发布任何代码,因此是出于猜测),示例3可以正常工作,但改为示例2。但是只有3和4是等效的! And now you call that ExtJS fault! 现在,您称该ExtJS错误!

You are executing code in an onLoad event or a Load event, perhaps like: 您正在onLoad事件或Load事件中执行代码,也许像这样:

$(window).load(function() {
    $('p').css('');
})

Remove this section and use only this in the javascript file and include it in a <Head> section: 删除此部分,并仅在javascript文件中使用此部分,并将其包括在<Head>部分中:

$('p').css('');

When you are coding in html, then it execute steps one by one. 当您使用html进行编码时,它会一步一步执行。 But when we use a separate file then it executes it slower than HTML code. 但是,当我们使用单独的文件时,它的执行速度要比HTML代码慢。

I think I can use those technique mentioned on the top. 我想我可以使用上面提到的那些技术。

I am sure it will work. 我相信它会起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM