jQuery Mobile-loadPage问题 [英] jquery mobile - loadPage issue
本文介绍了jQuery Mobile-loadPage问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在获取 jQuery-mobile 加载页面以将我的下一页加载到"content
" div
时遇到麻烦.
I am having trouble getting jQuery-mobile load page to load my next page into the "content
" div
.
我已将页面缩减为基本内容,下面是代码.
I have cut my page down to the basics and here is the code.
index.html:
index.html:
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>JQuery Mobile Load Page Test</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css">
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>
</head>
<body>
<div data-role="page">
<div id="containerTest" data-role="content">
<input type="button" id="nextPage" data-inline="true" value="Load Second Page"/>
</div> <!-- /content -->
</div> <!-- /page -->
<script>
$( "#nextPage" ).on( "click", function()
{
$.mobile.loadPage("nextPage.html",
{
pageContainer: $('#containerTest')
});
});
</script>
</body>
</html>
和nextPage.html
and nextPage.html
<div data-role="page">
<p>this is the next page</p>
</div> <!-- /page -->
推荐答案
我不认为您可以在另一个页面中加载页面,但是您可以尝试执行以下操作:
I don't think You can load a page inside another page, you could try something like this though:
$(document).on('pageinit', function(){
$( "#nextPage" ).on( "click", function(){
$('#containerTest').load('nextPage.html [data-role="content"]',function(){
$('.ui-page-active').trigger('create');
});
});
});
这将从容器内的第2页加载内容(<div data-role="content">
),然后在原始页面上触发create事件以增强所加载的内容
This will load the content (<div data-role="content">
) from page 2 inside the container, then it will trigger the create event on the original page to enhance the loaded content
这篇关于jQuery Mobile-loadPage问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文