在jquery中创建我自己的消息框

在jquery中创建我自己的消息框,jquery,jquery-mobile,Jquery,Jquery Mobile,我尝试在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({

我尝试在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>
函数创建对话框(标题、文本){
返回$(“”+text+“

”) .对话({ 可调整大小:false, 身高:140, 莫代尔:是的, 按钮:{ “确认”:功能(){ $(此).dialog(“关闭”); }, “取消”:函数(){ $(此).dialog(“关闭”); } } }); } 按我
我尝试了这个样本,但什么都没发生

编辑:

演示:

thsnk

你的代码很好,你只是忘记了库

dialog()方法来自jQueryUI。上面链接的JSFIDLE只添加了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");
                    }
                }
            });
        }
//之所以出现此代码,是因为SO需要一些代码
函数createDialog(标题、文本){
返回$(“”+text+“

”) .对话({ 可调整大小:false, 身高:140, 莫代尔:是的, 按钮:{ “确认”:功能(){ $(此).dialog(“关闭”); }, “取消”:函数(){ $(此).dialog(“关闭”); } } }); }
我看起来你在其他事情发生之前就回来了……我在jQuery 1.8.3和jQuery mobile 1.4.2上尝试了这一点,但什么都没有发生。我更新了我的问题这是一个可怕的依赖性问题。由于JSFIDLE的导入过程,在本例中仅选择框是不够的。我已经显式地向jqueryui添加了一个脚本标记,它似乎可以工作。