加载本地Java脚本文件 [英] Loading Local Java Script file

查看:167
本文介绍了加载本地Java脚本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的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 getScriptfunction 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 getScriptnothing 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屋!

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