Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery ui JQuery UI对话框-如何从对象添加按钮_Jquery Ui_Object_Jquery Ui Dialog - Fatal编程技术网

Jquery ui JQuery UI对话框-如何从对象添加按钮

Jquery ui JQuery UI对话框-如何从对象添加按钮,jquery-ui,object,jquery-ui-dialog,Jquery Ui,Object,Jquery Ui Dialog,我有以下代码: var bt = {} bt = { text: "OK", click: function () { // Deletefunction here... $(this).remove() } }, { text: "Cancel", click: function () { $(this).remove() } } $("#test").dialog({ title: "

我有以下代码:

var bt = {}

bt = {
    text: "OK",
    click: function () {
        // Deletefunction here...
        $(this).remove()
    }
}, {
    text: "Cancel",
    click: function () {
        $(this).remove()
    }
}

$("#test").dialog({
    title: "Confirm deletion",
    width: "300px",
    buttons: [bt]
})

为什么我只看到“确定”按钮,而没有看到“取消”按钮??jshiddle.

这是因为您分配给bt的任务与您认为的不同。它最终应用,相当于:

bt = {
    text: "OK",
    click: function () {
        // Deletefunction here...
        $(this).remove();
    }
};
// Stray, ignored object literal.
{
    text: "Cancel",
    click: function () {
        $(this).remove();
    }
};
如果您希望
bt
成为一个数组,请将其设置为:

var bt = [{
    text: "OK",
    click: function () {
        // Deletefunction here...
        $(this).remove();
    }
}, {
    text: "Cancel",
    click: function () {
        $(this).remove();
    }
}];

$("#test").dialog({
    title: "Confirm deletion",
    width: "300px",
    buttons: bt
});