jQuery UI Dialog Button Icons

后端 未结 12 1425
[愿得一人]
[愿得一人] 2020-11-29 02:40

Is it possible to add icons to the buttons on a jQuery UI Dialog? I\'ve tried doing it this way:

$(\"#DeleteDialog\").dialog({
    resizable: false,
    hei         


        
相关标签:
12条回答
  • 2020-11-29 03:06

    This version works without having to worry about the text in the buttons

    open: function() {
        $(this).parent().find('.ui-dialog-buttonpane button:first-child').button({
            icons: { primary: 'ui-icon-circle-close' }
        });
        $(this).parent().find('.ui-dialog-buttonpane button:first-child').next().button({
            icons: { primary: 'ui-icon-circle-check' }
        });
    }
    
    0 讨论(0)
  • 2020-11-29 03:11

    Or if you don't want to affect any other dialogs,

    open: function() {
        $(this).parent().find('.ui-dialog-buttonpane button:contains("Cancel")').button({
            icons: { primary: 'ui-icon-circle-close' }
        });
        $(this).parent().find('.ui-dialog-buttonpane button:contains("Ok")').button({
            icons: { primary: 'ui-icon-circle-check' }
        });
    }
    
    0 讨论(0)
  • 2020-11-29 03:12

    also you can add id or other attr to button, like this:

    buttons:[
                {
                    text: "Close",
                    id: "closebtn",
                    click: function() { $(this).dialog("close"); }
                }
            ],
    open: function() {
                $("#closebtn").button({ icons: { primary: "ui-icon-close" } });
            }
    
    0 讨论(0)
  • 2020-11-29 03:14

    Try this line to add the trash icon to the delete button. The sprite has to be in a separate element.

    $('.ui-dialog-buttonpane').find('button:contains("Delete")').prepend('<span style="float:left;" class="ui-icon ui-icon-trash"></span>');
    

    In order to prevent the icon from appearing on the top of the button:

    $('.ui-dialog-buttonpane')
        .find('button:contains("Delete")')
        .removeClass('ui-button-text-only')
        .addClass('ui-button-text-icon-primary')
        .prepend('<span class="ui-icon ui-icon-trash"></span>');
    
    0 讨论(0)
  • 2020-11-29 03:16

    I ran in the same issue. It seems jquery stores the text in an attribute called "text" in the button itself, and not as text inside the button.

    I solved it like this:

        $dialog.dialog({
            resizable:false,
            draggable:false,
            modal:true,
            open:function (event, ui) {
                $(this).parents('.ui-dialog').find('.cancel.ui-button').text('Cancel');
                //or you could use: $(this).parents('.ui-dialog').find('button[text="Cancel"]').text('Cancel');
                $(this).parents('.ui-dialog').find('.add.ui-button').text('OK');
            },
            buttons:[
                {
                    text:"OK",
                    click:function () {
    
                    },
                    "class":"add"
                },
                {
                    text:"Cancel",
                    click:function () {
    
                    },
                    "class":"cancel"
                }
            ]
        });
    
    0 讨论(0)
  • 2020-11-29 03:20

    i' tried this, and it works :)

    [....]
    open: function() {
                    $('.ui-dialog-buttonpane').
                        find('button:contains("Cancel")').button({
                        icons: {
                            primary: 'ui-icon-cancel'
                        }
                    });
    [....]
    
    0 讨论(0)
提交回复
热议问题