簡體   English   中英

Apache Cordova:在運行時更新index.html

[英]Apache Cordova: issue updating index.html at runtime

我們想報告一些問題,這些問題是我們使用Visual Studio Community 2013開發Cordova應用程序時在Windows Phone 8.1的運行時在index.html文件中添加新代碼行的問題。 似乎只有HTML標記可以正確讀取和執行,而不執行JS(包含在標記中或直接包含在元素標記中,例如使用onclick事件)。 我們在Android模擬器和物理設備上都運行了相同的項目,並且運行良好。 有人知道這是兼容性問題還是其他問題? 感謝您的關注和幫助。

代碼是:

INDEX.HTML:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>Tester</title>
    <link href="css/index.css" rel="stylesheet" />
</head>
<body>
    <input type="button" id="test" value="Prova x Emulatore wp" />
    <!-- Cordova reference, this is added to your app when it's built. -->
    <script src="cordova.js"></script>
    <script src="scripts/platformOverrides.js"></script>
    <script src="scripts/jquery-2.1.1.min.js"></script>
    <script id="last_script" src="scripts/index.js"></script>
</body>
</html>

INDEX.JS:

(function () {
    "use strict";


    document.addEventListener( 'deviceready', onDeviceReady.bind( this ), false );
    var logOb;
    function onDeviceReady() {
        navigator.notification.alert('ciao');
        // Handle the Cordova pause and resume events
        document.addEventListener( 'pause', onPause.bind( this ), false );
        document.addEventListener('resume', onResume.bind(this), false);
        document.getElementById('test').addEventListener('click', function () {
            var el1 = '<input type="button" id="Prova" value="Ciao"/>',
                el2 = '<script type="text/javascript">document.getElementById(\'Prova\').addEventListener(\'click\', function(){navigator.notification.alert(\'Ciao sono il bottone\')}, false);</script>';
            $('#test').after(el1);
            $('#last_script').after(el2);
        }, false);
        // TODO: Cordova has been loaded. Perform any initialization that requires Cordova here.
    };

    function onResume() { };

    function onPause() { };
} )();

TrialCode團隊。

這看起來像一個JQuery問題,在使用之前尚未完全加載。

我總是檢查DOM是否已准備好使用

$( document ).ready(......

然后檢查設備是否像您已經准備的那樣准備就緒。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM