一個既然你有這樣的標記改變的popup
內容的方式:
<div data-role="page" id="page1">
<div data-role="content">
<a id="btn2" href="#popup" data-role="button" data-transition="flip" data-rel="popup">Open a popup</a>
<div data-role="popup" id="popup" data-overlay-theme="a">
<h1>It's a popup</h1>
</div>
</div>
</div>
您可以處理popupbeforeposition
和/或popupafteropen
事件
$(document).on("pageinit", "#page1", function(){
$("#popup").on("popupbeforeposition", function(event, ui) {
$(this).append("<p>I've been added to popup!</p>");
});
$("#popup").on("popupafteropen", function(event, ui) {
$(this).append("<p>It has been added after I'm open!</p>");
});
});
另一個方法將在click
事件
鑑於標記
<a id="btn1" href="#" data-role="button" data-transition="flip">Dynamic popup</a>
<div data-role="popup" id="popup2" data-overlay-theme="e">
</div>
來創建(或更改)彈出窗口的內容
你可以做
$("#btn1").click(function(){
$("#popup2").html("<h1>Header</h1><p>This is the popup's message.</p>").popup("open");
});
UPDATE: 最後你可以把它放在一起:
$("#btn1").click(function(){
$.mobile.loading('show', {theme:"e", text:"Loading the content...", textonly:true, textVisible: true});
setTimeout(function(){
//Do some lengthy work here
doWork();
//Show the popup
$("#popup2").html("<h1>Header</h1><p>This is the popup's message.</p>").popup("open");
}, 50);
});
$("#popup2").on("popupafteropen", function(event, ui) {
$.mobile.loading('hide');
});
UPDATE2: 更新jsFiddle說明了一些冗長的工作
什麼是彈出( 「開」)呢? 什麼是load()呢? –
什麼是load()?我猜這是一個異步問題。嘗試查看「異步回調」 – elclanrs
您的選擇器是_wrong_'$(「mypopup」)',您的頁面中肯定沒有''元素。 –
undefined