admin管理员组文章数量:1390503
I am working on a project that will have hundreds of pages into on html page.
I am very concern about navigating this sub-pages using <a href=#ID" >
to move forward between sub-pages. Is there a way to use one button into every sub-page that will take me to the next sub-page in a way that I dont have to write every sub-page ID into every "Next" button ?
I am working on a project that will have hundreds of pages into on html page.
I am very concern about navigating this sub-pages using <a href=#ID" >
to move forward between sub-pages. Is there a way to use one button into every sub-page that will take me to the next sub-page in a way that I dont have to write every sub-page ID into every "Next" button ?
2 Answers
Reset to default 6Back button :
jQuery Mobile has out of box solution for a back button on every page.
<script>
$(document).on('mobileinit', function () {
$.mobile.ignoreContentEnabled = true;
});
</script>
This code must be placed before jQuery Mobile initialization, like this:
<head>
<title>Share QR</title>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<link rel="stylesheet" href="http://code.jquery./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./mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
</head>
Next button :
This one is a little bit tricky, auto generated next button will only work if you have 1 html with multiple pages solution. This will provide you with an information of a next page in line, so to create next button use this code:
$(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());
}
});
Working example :
Here's a working example of this solution: http://jsfiddle/Gajotres/BnB7X/
If you have more questions feel free to ask.
I solved it this way:
$(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 });
});
});
Then place the previous/next buttons where ever you like, just make sure that the previous button class prevBtn and the next button class nextBtn.
For example:
<a href="#" class="ui-btn prevBtn">Previous</a>
<a href="#" class="ui-btn nextBtn">Next</a>
本文标签: javascriptJquery Mobile Add next and previous buttonsStack Overflow
版权声明:本文标题:javascript - Jquery Mobile: Add next and previous buttons - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744590754a2614475.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论