2014-05-16 45 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