How to add my custom buttons with ids to a dialog-modal jquery object

╄→尐↘猪︶ㄣ 提交于 2019-12-12 01:39:23

问题


I would like to add custom buttons (with ids, so they can be clicked and have an action happen), added to my dialog modal object.

I would like there to be some text, and then have the buttons below the text in the modal dialog box.

Right now I have:

Javascript:

$("#dialog-modal").dialog({
    autoOpen: false,
    resizable: false,
    draggable: false,
    height: 250,
    width: 500,
    modal: true,
    dialogCLass: 'main-dialog-class'
});

$("#dialog-modal").dialog("open");

var text = '';
text = "This is a test";

$('#dialog-modal').text(text);

HTML:

<div id="dialog-modal" title="{{$artist->stage_name}} in {{Auth::user()->city}}!"></div>

I would like to add a button that looks like:

<a class="facebook-button" id="facebook" style="color: white; font:14px / 14px 'DINMedium','Helvetica Neue',Helvetica,Arial,sans-serif;">Share on Facebook</a>

Thank you for your help.


回答1:


use .html() to add html contents like button or a tags etc to div

you can use to you a tag like this :-

$('#dialog-modal').html('<a class="facebook-button" id="facebook" style="color: white; font:14px / 14px 'DINMedium','Helvetica Neue',Helvetica,Arial,sans-serif;">Share on Facebook</a>');



回答2:


You can use buttons option to add custom buttons on your dialog:

add the option like this:

    $( "#dialog-modal" ).dialog({ 
        buttons: [{ text: "Share on Facebook",
                click: function() {
                    // your function here
                }
        }]
    });


来源:https://stackoverflow.com/questions/17849513/how-to-add-my-custom-buttons-with-ids-to-a-dialog-modal-jquery-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!