首页 > 解决方案 > 如何使用cordova在我的index.js中添加我的功能“新页面”

问题描述

我是移动应用程序开发的新手,我想知道如何简化我的代码。我想在我的 index.js 页面中添加我的脚本。

您可以看到我的函数转到另一个正在运行的页面,但我不喜欢将我的 javascript 代码放在与我的 html/css 代码相同的页面中。

谢谢 :)

(function () {
    "use strict";

    document.addEventListener( 'deviceready', onDeviceReady.bind( this ), false );

    function onDeviceReady() {
        // Gérer les événements de suspension et de reprise Cordova
        document.addEventListener( 'pause', onPause.bind( this ), false );
        document.addEventListener('resume', onResume.bind(this), false);

        document.getElementById("goPageOne").onclick = function goPageOne();
        
        // TODO: Cordova a été chargé. Effectuez l'initialisation qui nécessite Cordova ici.
        var parentElement = document.getElementById('deviceready');
        var listeningElement = parentElement.querySelector('.listening');
        var receivedElement = parentElement.querySelector('.received');
        listeningElement.setAttribute('style', 'display:none;');
        receivedElement.setAttribute('style', 'display:block;');
        
        // ajout d'une fonction vibration
        //navigator.vibrate(2000);
    };

    function onPause() {
        // TODO: cette application a été suspendue. Enregistrez l'état de l'application ici.
        
    };

    function onResume() {
        // TODO: cette application a été réactivée. Restaurez l'état de l'application ici.
        
    };

    //Function go to another page
    

});
<button id="goPageOne">Memo</button>

<script type="text/javascript">
    document.getElementById("goPageOne").onclick = function () {
        location.href = "../www/homememo.html";
    };
</script>

标签: javascriptcordova

解决方案


好的,科尔多瓦的 window.open 有一些东西,所以我只是用更简单的东西改变了功能,没有任何功能。我已经用一个 href 替换了这个函数,比如:

<form action="index.html">
<button type="submit" id="b1">Quitter</button>
</form>


推荐阅读