繁体   English   中英

Jquery Mobile:添加下一个和上一个按钮

[英]Jquery Mobile: Add next and previous buttons

我正在开发一个在html页面上有数百页的项目。

我非常担心使用<a href=#ID" >在子页面之间向前移动来浏览这些子页面。有没有办法在每个子页面中使用一个按钮将我带到下一个子页面在某种程度上,我没有必要将每个子页面ID写入每个“下一步”按钮?

返回键 :

jQuery Mobile为每个页面上的后退按钮提供了开箱即用的解决方案。

<script>
    $(document).on('mobileinit', function () {
        $.mobile.ignoreContentEnabled = true;
    });
</script> 

此代码必须放在jQuery Mobile初始化之前,如下所示:

<head>
  <title>Share QR</title>
  <meta name="viewport" content="width=device-width, initial-scale=1"/>     
  <link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />   
  <script>
    $(document).on('mobileinit', function () {
        $.mobile.ignoreContentEnabled = true;
    });
  </script>    
  <script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
</head>

下一步按钮:

这个有点棘手,自动生成的下一个按钮只有在你有1个html的多页解决方案时才能工作。 这将为您提供下一页的信息,因此要创建下一个按钮,请使用以下代码:

$(document).on('pagebeforeshow', '[data-role="page"]', function(){       
    var nextpage = $(this).next('div[data-role="page"]');
    if (nextpage.length > 0) {    
        $.mobile.activePage.find('[data-role="header"]').append($('<a>').attr({'href':'#'+nextpage.attr('id'),'data-theme':'b'}).addClass('ui-btn-right').html('Next').button());
    }  
});  

工作范例:

以下是此解决方案的一个有效示例: http//jsfiddle.net/Gajotres/BnB7X/

如果您有更多问题,请随时提出。

我这样解决了:

$(document).ready(function() {

    $('.nextBtn').click(function() {
        $page = $(this).closest('div[data-role="page"]').next();
        $.mobile.changePage( $page, { transition: "slide", changeHash: false });
    });

    $('.prevBtn').click(function() {
        $page = $(this).closest('div[data-role="page"]').prev();
        $.mobile.changePage( $page, { transition: "slide", reverse: true, changeHash: false });
    });

});

然后将上一个/下一个按钮放在您喜欢的位置,只需确保前一个按钮类prevBtn和下一个按钮类nextBtn。

例如:

<a href="#" class="ui-btn prevBtn">Previous</a>
<a href="#" class="ui-btn nextBtn">Next</a>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM