Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/459.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Phonegap-如何从索引页调用另一个文件中的一个javascript函数?_Javascript_Iphone_Ios_Cordova_Phonegap Plugins - Fatal编程技术网

Phonegap-如何从索引页调用另一个文件中的一个javascript函数?

Phonegap-如何从索引页调用另一个文件中的一个javascript函数?,javascript,iphone,ios,cordova,phonegap-plugins,Javascript,Iphone,Ios,Cordova,Phonegap Plugins,我是一个iOS和PhoneGap新手。我有index.html文件和一个名为MyClass.js的javascript文件 在MyClass.js中,我有一个函数- var MyClass = { testfunc: function() { navigator.notification.alert("Success : \r\n"); } } 我试图从index.html函数调用它,比如- MyClass.testfunc(); 在我的Phonegap.plist文件中,我有一

我是一个iOS和PhoneGap新手。我有index.html文件和一个名为MyClass.js的javascript文件

在MyClass.js中,我有一个函数-

var MyClass = {

testfunc: function() {
    navigator.notification.alert("Success : \r\n");
}

}
我试图从index.html函数调用它,比如-

MyClass.testfunc();

在我的Phonegap.plist文件中,我有一个条目MyClass MyClass,它是一个具有字符串类型的键值对。但是我没有得到警告。我做错了什么

您是否已在index.html中包含以下内容:

<script src="MyClass.js"></script>


这将允许您在index.html文件中使用MyClass.js函数

您的警报标记错误

navigator.notification.alert(
    'Some Alert Text here', // alert message
    successCallback, // callback function
    'Alert Title, // alert title
    'OK' // button text
);

您好,您可以尝试以下代码:

// MyClass.js
var MyClass = {
    testFunction: function() {
        alert("hi there");
    }
};

// index.html
<html>
<head>
</head>
<body>
    <script src="MyClass.js"></script>
    <script src="phonegap-1.3.0.js"></script>
    <script type="text/javascript">
        document.addEventListener("deviceready", function() {
            navigator.notification.alert("hi there \r\n");
            //alert("hi there \r\n");
        });
    </script>
</body>
</html>
//MyClass.js
var MyClass={
testFunction:function(){
警惕(“你好”);
}
};
//index.html
document.addEventListener(“deviceready”,函数(){
navigator.notification.alert(“你好\r\n”);
//警报(“你好”\r\n);
});

我这样做了,但仍然无法调用外部函数:(不是真的。只有“Success:\r\n”应该也可以。当我将它放在脚本标记内的index.html文件中时,它也可以工作。我在onDeviceReady()中调用它)超级奇怪。你加载js文件的顺序是什么?在你的phonegap js之前还是之后?你是什么意思?我在我自己的文件之前指定这正是我的意思,非常奇怪。有时候你加载脚本的顺序会影响它们,但你做得对。我不完全确定……你有没有任何错误?e是什么你有日志吗?