【问题标题】:jQuery mobile does not add back button?jQuery mobile 没有添加返回按钮?
【发布时间】:2013-05-02 14:59:36
【问题描述】:

我的脑袋:

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title></title>
    <script src="<?php echo base_url();?>/assets/js/vendor/modernizr-2.6.2.min.js"></script>
    <meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0 target-densitydpi=medium-dpi'/>
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.css" />

    <!--jQuery, mobile options, JQM-->
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <script>window.jQuery || document.write('<script src="<?php echo base_url();?>assets/js/vendor/jquery-1.9.1.min.js"><\/script>')</script>
    <script src="<?php echo base_url();?>assets/js/transition.js"></script>
    <script src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>

    <script src="http://ricostacruz.com/jquery.transit/jquery.transit.min.js"></script>
    <link rel="stylesheet" href="<?php echo base_url();?>/assets/css/normalize.css">
    <link rel="stylesheet" href="<?php echo base_url();?>/assets/css/main.css">
</head>

transition.js:

$(document).bind("mobileinit", function() { 

    //back button
    $.mobile.page.prototype.addBackBtn = true;
    if (navigator.userAgent.indexOf("Android") != -1) { $.mobile.defaultPageTransition = 'none'; $.mobile.defaultDialogTransition = 'none'; } else {
        $.mobile.defaultPageTransition = 'pop';
    } 
});

为什么不添加?

【问题讨论】:

  • 我认为您对document.write() 的调用最终会嵌套两个&lt;script&gt; 元素。您的 window.jQuery || &lt;include script&gt; 模式可能不可行。

标签: javascript jquery mobile-application jquery-mobile


【解决方案1】:

确保这个 sn-p 是在 jQuery 库加载之后但在 jQueryMobile 库加载之前:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).bind("mobileinit", function() { 

    //back button
    $.mobile.page.prototype.options.addBackBtn = true;
    if (navigator.userAgent.indexOf("Android") != -1) { $.mobile.defaultPageTransition = 'none'; $.mobile.defaultDialogTransition = 'none'; } else {
        $.mobile.defaultPageTransition = 'pop';
    } 
});
</script>
<script src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>

参考:jquery-mobile still "No Back Button" (Beta 2)

【讨论】:

  • 它是$.mobile.page.prototype.options.addBackBtn。没有.options,它将无法工作。
  • 这正是我正在做的。还有@FrédéricHamidi 也不能解决问题。
  • 您是否尝试过加载较旧的 jquery 库? 1.7 或 1.8。最新的可能需要迁移插件。
  • Frédéric 的解决方案运行良好,您可能做错了什么。
  • @Gajotres 可能。但是我将包含的代码保留为唯一的 Javascript 代码,但它仍然无法正常工作。很奇怪。
猜你喜欢
  • 1970-01-01
  • 2012-04-27
  • 2018-11-28
  • 1970-01-01
  • 2013-03-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-12-23
相关资源
最近更新 更多