2012-01-16 38 views
1

我在我的應用程序中使用PhoneGap的這個樣子,還要注意應用程序是由jQuery Mobile的風格,爲什麼我的PhoneGap按鈕沒有反應

<meta name="viewport" content="width=device-width, initial-scale=1"> 

    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" /> 

    <script src="http://code.jquery.com/jquery-1.6.4.min.js"></script> 
    <script src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js"></script> 
    <script type="text/javascript" charset="utf-8" src="phonegap-1.3.0.js"></script> 

我有這個網站,

<div id="sync" data-role="page"> 
    <div data-role="header" data-position="inline"> 
     <a data-rel="back" data-icon="back">Back</a> 
     <h1>Sync</h1> 
    </div> 
    <div data-role="content"> 
     <button onclick="sync()">Sync</a></button> 
    </div> 
</div> 

我已經編譯了這個Android版本,並讓它在我的Android手機上工作。

但是,那裏所謂的「同步」按鈕並不總是響應。我點擊按鈕並且sync()方法每次都不會被調用。我發現自己多次點擊該按鈕。當我點擊它時,我可以看到按鈕移動,它通過繪製自己被推入來響應,但同步方法沒有被調用。

同步方法開始就是這樣,

function sync() 
{ 
    alert("syncing"); 
    $.mobile.loadingMessage = "syncing"; 
    $.mobile.showPageLoadingMsg(); 

我把警報在調試的目的。

UPDATE:

有人指出我的HTML中有一個額外的標籤。我已刪除它下面,但問題依然存在,

<div data-role="content"> 
    <button onclick="sync()">Sync</button> 
</div> 

回答

1

開玩笑的回答:你按下按鈕夠硬?

可能問題的答案:

<button onclick="sync()">Sync</a></button> 
           ^^^^---dangling tag 

那是</a>可能按鈕破裂的原因是什麼?

2

我的應用程序中有類似的問題。我嘗試了兩種不同的東西,但我不確定是否修復了它。

  1. 我在腳本標記中添加了charset =「utf-8」。

  2. 我將按鈕點擊功能移到了它自己的腳本標記中。我認爲在其他JavaScript塊中存在一個錯誤,它阻止了按鈕點擊功能在該腳本塊中工作。所以你可以嘗試隔離按鈕點擊JavaScript,看看是否有幫助。

相關問題