加载本地Java脚本文件 [英] Loading Local Java Script file
问题描述
在我的index.html
上,我正在执行以下操作:
On my index.html
I am doing the following:
<script src="jquery/jquery.js"></script>
<script src="managment.js"></script>
<script src="jquery/jquery.mobile-1.1.0.js"></script>
进行一些计算后,我需要使用 managment.js 文件中的函数:
After doing some calculation, I have the need of using a function from the managment.js file:
$.getScript("managment.js", function(){
alert("Script loaded and executed.");
login();
});
}
最后是managment.js
文件:
<script type="text/javascript">
function login(){
alert("asdasdasdasdasdasd");
}
</script>
我的问题是,从未调用login()
函数.实际上,我在getScript
函数中具有的警报也未调用,但奇怪的是,如果我检查jquery.js
文件是否已加载,则会调用该警报.另外,如果我尝试不执行getScript
调用login(),则不会发生任何事情.我的文件结构如下:
My issue, is that the login()
function is never called. Actually the alert I have inside getScript
function is not called either, but the strange thing is that if I check if the jquery.js
file is loaded the alert is called. More, if I try to call login() without doing getScript
nothing happens has expected. My files structure is the following:
(注意:您可以看到我正在使用2个managment.js
文件.我尝试了两种方法来查看问题是否出在文件路径上.)
(note: you can see that I am using 2 managment.js
files. I tried both approaches to see if the problem was with the path of the file.)
我在这里想念什么?出于相关性,我使用的是PhoneGap,但这在浏览器上也不起作用.
What am I missing here? For relevance, I am using PhoneGap, but this isn't working on the browser as well.
推荐答案
management.js
文件不应包含<script type="text/javascript">
标记.应该是:
The management.js
file should not contain the <script type="text/javascript">
tag. It should be:
function login(){
alert("asdasdasdasdasdasd");
}
希望有帮助! :)
这篇关于加载本地Java脚本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!