将jQuery UI Dialog的按钮更改为简单链接?

4

我在jquery UI对话框中定义了一个自定义按钮:

$("#myDlg").dialog({
        modal: true,
        buttons: {
            'My Custom Link': function () {
                alert('my custom message');
            },
            'Close': function () {
                $(this).dialog('close');
            }
        }
    });

我想将按钮“My Custom Link”显示为HTML链接,而不是默认的按钮样式。我该怎么做?谢谢。

1
精确副本:https://dev59.com/C07Sa4cB1Zd3GeqP5azU - Pencho Ilchev
1个回答

6
默认的 jQuery 选项不支持添加链接...然而,您可以向包装器中添加任何您想要的内容...请参见下面的示例:
$(function() {
    $("#myDlg").dialog({
        modal: true,
        buttons: {
            'Close': function() {
                $(this).dialog('close');
            }
        }
    })
    .parent()
    .find('.ui-dialog-buttonset')
    .prepend('<a href="javascript:void(0);" id="myCustomLink">My Custom Link</a>');

    $('#myCustomLink').click(function () {
        alert('my custom message');
    });
});

DEMO


这正是我想要的!非常感谢您提供演示。+1 - Niner

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接