【问题标题】:jquery mobile page exits when clicking a button on the page单击页面上的按钮时jquery mobile页面退出
【发布时间】:2015-02-14 08:23:02
【问题描述】:

我有几个这样定义的页面:

   <div data-role="page" id="home">
      ...
   </div>

   <div data-role="page" id="settings">
      ...
      <button id="testSettingsButton">Test</button>
   </div>

javascript 看起来像这样:

    $(document).on("touchend", "#testSettingsButton", function(e) {

        try {
           // connect to remote database
           // an error is thrown and caught by the db library code
        } catch (err) {
           // not reached
        }
    });

当用户点击Test按钮时,jquery mobile会显示home屏幕而不是停留在setting屏幕上。

为什么会这样?如何修复或调试此问题?

我在 Cordova 4.1.2 上使用 Jquery Mobile 1.4.5。

【问题讨论】:

    标签: javascript android jquery cordova jquery-mobile


    【解决方案1】:

    解决方案非常简单——我忘记在方法中添加e.preventDefault(); 。添加这个解决了这个问题。

    $(document).on("touchend", "#testSettingsButton", function(e) {
        e.preventDefault();
        try {
           // connect to remote database
           // an error is thrown and caught by the db library code
        } catch (err) {
           // not reached
        }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多