创建Jquery对话框UI后如何添加按钮 [英] How to add Buttons after created a Jquery Dialog UI

查看:110
本文介绍了创建Jquery对话框UI后如何添加按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个jquery对话框,需要向其中添加按钮.

I want to create a jquery dialog and needs to add buttons to it.

我正在使用以下代码,该代码在IE中可以正常工作,但在Mozilla中却不能.

I'm using the following code which works fine in IE but not in Mozilla.

有人能找出这里的问题吗?

Can any one figure out what is the issue here?

function dialog_box(dynDiv, rootTemplate) {
    var dialog_buttons = rootTemplate.buttons;
    var dialog = $("#" + dynDiv.id).dialog({
        hide: "explode",
        title: rootTemplate.etype,
        buttons:'',
        text: rootTemplate.text,
        resizable: true,
        minWidth: 200,
        minHeight: 150,
        close: function () {
            $(dialog).dialog('destroy').remove();
        }
    });


    var buttonSet = $("#" + dynDiv.id).parent().find('.ui-dialog-buttonset');
    $.each(dialog_buttons, function (index, props) {
        var newButton = $('<button></button>', {
            id: "btn" + dynDiv.id + props.id,
            text: props.text
        });
        newButton.button().unbind().on("click", props.handler);

        $(buttonSet).append(newButton);      
    });


}

示例

推荐答案

尝试以下方法:

// Retrieve buttons hash
var buttons = dialog.dialog("option", "buttons"); 
// Extend the hash (so you're able to keep the old buttons)
$.extend(buttons, { props.text: props.handler } );
// Set it again
dialog.dialog("option", "buttons", buttons);

这篇关于创建Jquery对话框UI后如何添加按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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