[英]How to load external html content into a div inside a page using jquery mobile
標記當前頁面的一部分。
<div class="que-plc">
<div class = "questionHolder">
<div class = "questionBorder">
<h3>A question?</h3>
<div>
<div ><a id="goto-que1" class="to-next-que">NEXT</a></div>
</div>
</div>
</div>
</div>
必須加載到當前頁面的標記:
HTML -- que1.html:
<div class = "questionHolder">
<div class = "questionBorder">
<h3>Question Here?</h3>
<div data-type="horizontal">
<div><a id="goto-que2" data-role="button" class="to-next-que">NEXT</a></div>
</div>
</div>
</div>
HTML -- que2.html:
<div class = "questionHolder">
<div class = "questionBorder">
<h3>Question Here?</h3>
<div data-type="horizontal">
<div><a id="goto-que3" data-role="button" class="to-next-que">NEXT</a></div>
</div>
</div>
</div>
加載que1.html和que2.html的javascript:
$("a.to-next-que").click(function(){
alert(this.id)
var cur_id = this.id.toString();
$(".questionHolder").remove();
var last = cur_id.length
cur_id = cur_id[last - 1];
$.get('level/level1/que'+cur_id+'.html',function(question) {
$('.que-plc').html(question).trigger('create');
});
});
問題出在que1.html
被加載到dom i,e內部之后。 que-plc
容器,則連續的點擊不會將que2.html, que3.html ... to the dom
加載que2.html, que3.html ... to the dom
。 怎么了?
我正在使用jquery-mobile 1.0.1
,所以使用$ .mobile.loadPage和$ .mobile.changePage會導致錯誤。
並通過a link whose data-ajax="false"
不會加載page2.html
的javascript a link whose data-ajax="false"
從page1.html to page2.html
導航page1.html to page2.html
。
那是:
<body>
<div data-role="page">
</div>
<script src="play.js"></script>
play.js將wont be available in
page2.html`中使用。 如何糾正?
你可以這樣使用
$('#div_content').load("page.html");
單擊按鈕加載頁面
$('#button').click(function(){
$('#div_content').load('html.page');
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.