我有以下代碼使用jQuery手機創建彈出。彈出窗口被創建並且一個窗體被創建並被附加到彈出窗口以及兩個按鈕。此代碼確實有用,但我想知道是否有更好的方法來實現我的預期目標。jQuery Mobile最好的方式來創建彈出和動態內容
//create a div for the popup
var $popUp = $("<div/>").popup({
dismissible : false,
theme : "a",
overlyaTheme : "a",
transition : "pop"
}).bind("popupafterclose", function() {
//remove the popup when closing
$(this).remove();
});
//create a title for the popup
$("<h2/>", {
text : PURCHASE_TITLE
}).appendTo($popUp);
//create a message for the popup
$("<p/>", {
text : PURCHASE_TEXT
}).appendTo($popUp);
//create a form for the pop up
$("<form>").append($("<input/>", {
type : "password",
name : "password",
placeholder : PASSWORD_INPUT_PLACEHOLDER
})).appendTo($popUp);
//Create a submit button(fake)
$("<a>", {
text : SUBMIT_BTN_TXT
}).buttonMarkup({
inline : true,
icon : "check"
}).bind("click", function() {
$popUp.popup("close");
that.subscribeToAsset(callback);
}).appendTo($popUp);
//create a back button
$("<a>", {
text : BACK_BTN_TXT,
"data-jqm-rel" : "back"
}).buttonMarkup({
inline : true,
icon : "back"
}).appendTo($popUp);
$popUp.popup("open").trigger("create");
其工作http://jsfiddle.net/Palestinian/YCZrg/我喜歡它。很有創意的想法。正如Gajotres所說,用'.on'代替'.bind'。 – Omar
感謝奧馬爾,我正在寫一個很小的HTML標記的應用程序,所以認爲這將是最好的方法 – user1812741
只有我不喜歡的是它看起來有點「哈克」你對此有何看法? – user1812741