Apache Cordova:运行时发布更新索引.html

Apache Cordova: issue updating index.html at runtime

本文关键字:更新索引 html 运行时 Cordova Apache      更新时间:2023-09-26

我们想报告我们在开发带有Visual Studio Community 2013的Cordova应用程序时面临的一些问题,在Windows Phone 8.1运行时在index.html文件中添加新的代码行。似乎只有 HTML 标签被正确读取和执行,而不是 JS(包含在标签中或直接包含在元素标签中,例如使用 onclick 事件)没有被执行。我们在Android模拟器和物理设备上运行了相同的项目,并且运行良好。有谁知道这是兼容性问题还是其他问题?感谢您的关注和帮助。

代码为:

索引.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>

索引.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() { };
} )();

试用代码团队。

看起来像一个JQuery问题,在使用之前它没有完全加载。

我总是检查 DOM 是否已准备好使用

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

然后检查设备是否像您一样准备就绪。