我尝试在jQuery-mobile中执行我自己的消息框,如下所示:
使用jQuery 1.8.3和jQuery-mobile 1.4.2
function createDialog(title, text) {
return $("<div class='dialog' title='" + title + "'><p>" + text + "</p></div>")
.dialog({
resizable: false,
height: 140,
modal: true,
buttons: {
"Confirm": function () {
$(this).dialog("close");
},
"Cancel": function () {
$(this).dialog("close");
}
}
});
}
<button onclick="createDialog('Confirm deletion!', 'Do you really want to delete this package?')">press me</button>
我试试这个样本 - 但没有任何事情发生......
编辑:
演示:http://jsfiddle.net/goldsoft/qd5dy4dy/5/
thsnk
答案 0 :(得分:1)
http://jsfiddle.net/qd5dy4dy/2/
您的代码很好,您只是忘记了库。
dialog()方法来自jQueryUI。上面链接的jsfiddle只添加了jquery和jqueryUI。
//This code is here because SO requires some code
function createDialog(title, text) {
return $("<div class='dialog' title='" + title + "'><p>" + text + "</p></div>")
.dialog({
resizable: false,
height: 140,
modal: true,
buttons: {
"Confirm": function () {
$(this).dialog("close");
},
"Cancel": function () {
$(this).dialog("close");
}
}
});
}