0

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

的代碼是:

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隊。

回答

0

這看起來像一個JQuery問題,它在使用前沒有完全加載。

我總是檢查DOM準備好使用

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

,然後檢查設備是否準備好喜歡你做的事。