How do I close a dialog using jQuery?

前端 未结 5 1106
攒了一身酷
攒了一身酷 2021-02-02 11:09

I am using the code below to create a jQuery UI Dialog widget dynamically:

 $(function () {
        var Selector = $(\"a:contains(\'sometext\')\");
        $(Sel         


        
5条回答
  •  时光说笑
    2021-02-02 11:21

    Personally, I managed in this way:

    1) Build the html of the dialog, with two span with xxx as default value

    There are two variables: xxx and xxx

    2) Make the div ready for being a dialog

    $(function() {
        $( "#dialog1").dialog({
        autoOpen:false,
            modal: true,
            buttons: {
            "Button 1": function() {
                $(this).dialog( "close" );
            },
            "Button 2": function() {
                $(this).dialog( "close" );
            }
        }
        });
    });
    

    3) And modifying the value of the two spans with this function, before firing up the dialog:

    function showDialog(value1,value2){
        $("#var1").html(value1);
        $("#var2").html(value2);
        $( "#dialog1").dialog('open');
    } 
    

    4) So when you need it, call the function in this way

    showDialog('tom','jerry'); 
    

    You can try this at http://jsfiddle.net/sekmo/L46vb/1/

提交回复
热议问题