我有以下代码使用 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");