簡體   English   中英

單頁應用程序的phonegap中的javascript

[英]javascript in phonegap for single page application

我嘗試使用Phonegap將Web應用程序轉換為Android應用程序。

該應用程序非常簡單:html,javascript,css。 從邏輯上講,它是一個頁面,其內容由一個簡單的javascript代碼更改(沒有任何外部庫)。

問題是,javascript僅適用於原始頁面上顯示的項目。 如果某個項目是由於javascript函數而出現的,並且為其分配了另一個javascript函數,則該另一個函數將永遠不會執行。

可能是什么原因? 我該如何改善這種情況?

更新:

問題是,如果有人在桌面瀏覽器窗口中看到該應用程序,則定義了該文檔的form1屬性(它出現在step3上),而對於移動應用程序卻並非如此。
演示:

<html>
<head>
<script  type="text/javascript">


document.onclick = function( whichOne ){ 
    whichOne = whichOne ? whichOne : window.event;
    thisButton = whichOne.target ? whichOne.target : whichOne.srcElement;
    if (thisButton.name) {
        if (thisButton.value == 'Submit') { 
            if (undefined != document.form1){
                alert("yes form1");
            }
            else {
                alert("no form1");
            }
        }
        else if (thisButton.name == 'b1') { 
            var iner ='<center>step 2</center>';
            un1(thisButton.title,iner);
            var oid=thisButton.title;
            iner = t4a(oid,thisButton.name);
            setTimeout( function() { un1(oid,iner);},1000);
        }
    }
}

function un1(id,iner){
    var ele = document.getElementById(id);
    ele.innerHTML = iner;
}

function t4a (id,ara){
    var i; 
    var out="<form name='form1'><center>step 3<table border='1'>"; 
    for (i=0;i < 2;i++){
        out +="<tr><td align='left'>"+i+".</td><td align='right'><input type='text'  name='f"+i+"'></td></tr>";
    }
    out+="</table><input type='button' name='a"+ara+"' title='"+id+"' value='Submit'
></center></form>";
    return out;
}

</script>
</head>

<body>
<center>        
<form >
<div id ="b1">
<input type="button" name="b1" title="b1" value="Butt">
</div>
</form>
</center>
</body>
</html>
<form >
<div id ="b1">
<input type="button" name="b1" title="b1" value="Butt">
</div>
</form>

並且您在div“ b1”內添加了一個表格...因此在表格內添加了表格? 更改為

<div id ="b1">
<form >
<input type="button" name="b1" title="b1" value="Butt">
</form>
</div>

它應該工作。

暫無
暫無

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

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