我可以动态地向Jquery UI对话框添加按钮吗? [英] Can I dynamically add buttons to a Jquery UI Dialog box?

查看:54
本文介绍了我可以动态地向Jquery UI对话框添加按钮吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试根据一些输入将新按钮添加到jquery UI对话框中.

I am trying to add a new button to a jquery UI Dialog box based upon some input.

我的代码如下:

function editTour(ID, myDate) {
$.post("/Admin/EditTour", { TourID: ID },
        function (data) {
            $('#EditTour').html(data);
            $('#EditTour').dialog({
                modal: true,
                width: 400,
                resizable: false,
                title: formatDate(myDate),
                buttons: {
                    "Save": function () {
                      //some junk logic removed
                     },
                    "Cancel": function () {
                        $(this).dialog("close");
                    }
                }
            });

        });   //end post
}

如果传递的ID为0,我想在此功能中添加一个删除"按钮.

What I want to do in this function is add a "Delete" button if the ID passed in is 0.

我知道我可以创建一个editTour函数的剪切和粘贴副本以手动添加删除"按钮...但是我希望有一些更干净的东西.

I know I can just create a cut and paste copy of the editTour function to manually add in the "Delete" button... but I was hoping for something cleaner.

推荐答案

尝试一下,可能会对您有所帮助.

Try this, it may help you.

function editTour(ID, myDate) {
    $.post("/Admin/EditTour", { TourID: ID },
        function (data) {
            $('#EditTour').html(data);
            $('#EditTour').dialog({
                modal: true,
                width: 400,
                resizable: false,
                title: formatDate(myDate)
            });

            var myButtons = {
                "Save": function () {
                    //some junk logic removed
                },
                "Cancel": function () {
                    $(this).dialog("close");
                }
            };

            if(ID == 0) {
                myButtons["Delete"] = function() {
                    // Delete logic here.
                }
            }

            $('#EditTour').dialog('option', 'buttons', myButtons);
        }
    );   //end post
}

这篇关于我可以动态地向Jquery UI对话框添加按钮吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆