2014-05-16 47 views
0

我只是試圖實現一個導航到單獨的錨標記,當用戶點擊從購物車頁面的繼續按鈕。

這是一個使用Cordova的移動應用程序,雖然這個函數調用是JQuery。

的HTML是

<a id="cart-continue" data-theme="none" class="cart-continue continue-button header-button">Continue</a> 

的JS在app.js

$("#cart-continue").click(function(){ 
    console.log("**Entered the Click for Continue**"); 
    if(cart.itemCount() == 0) 
     { 
      return false; 
     } 
    if (Status == "true") 
     { 
      $.mobile.changePage("#card-message"); 
     } 
    else 
     { 
      $.mobile.changePage("#may-we-suggest"); 
     } 
}); 

我用簡單的函數調用之前還真沒見過的問題,我們也將應用程序的服務器和呼叫它來自地址。 可能會發生什麼情況,不允許我使用適當的對象的ID並進行函數調用?

+0

從您的上下文中不確定,但是您是否將它包裝在document.ready中? –

+1

我把你的代碼扔在一支筆裏,並對其進行測試。它工作正常。 http://codepen.io/The_Animator/pen/eujtC – Derek

+0

不,它在$(#Page).live(function(){}) – Keeano

回答

3

這是一個容易犯的錯誤。您需要停止錨標記的默認事件。這樣做:

$("#cart-continue").click(function(e){ 
    e.preventDefault() 
    console.log("**Entered the Click for Continue**"); 
    if(cart.itemCount() == 0) 
     { 
      return false; 
     } 
    if (Status == "true") 
     { 
      $.mobile.changePage("#card-message"); 
     } 
    else 
     { 
      $.mobile.changePage("#may-we-suggest"); 
     } 
}); 
+0

http://jsfiddle.net/uzD4q/ –

+0

Thnaks,這有助於退出一點! – Keeano