Phonegap - Как вызвать одну функцию JavaScript в другом файле со страницы индекса? - PullRequest
0 голосов
/ 01 марта 2012

Я новичок в iOS и PhoneGap. У меня есть файл index.html и файл javascript с именем MyClass.js.

В моем MyClass.js у меня есть функция -

var MyClass = {

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

}

Я пытаюсь вызвать его из функции index.html как -

MyClass.testfunc();

В моем файле Phonegap.plist у меня есть запись MyClass-Myclass в виде пары ключ-значение с типом String. Однако я не получаю предупреждение. Что я делаю неправильно?

Ответы [ 3 ]

1 голос
/ 01 марта 2012

Неверная разметка для вашего предупреждения ...

navigator.notification.alert(
    'Some Alert Text here', // alert message
    successCallback, // callback function
    'Alert Title, // alert title
    'OK' // button text
);
1 голос
/ 01 марта 2012

Включили ли вы в свой index.html следующее:

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

Это позволит вам использовать функции MyClass.js в вашем файле index.html

0 голосов
/ 08 марта 2012

Привет, можешь попробовать следующий код:

// 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>
...