Trigger event on dialog box open

后端 未结 4 1500
误落风尘
误落风尘 2021-02-05 06:18

My dialog box is defined under the div

#dialogbox

When the dialog box opens i want to trigger an event such that it alerts open. The code im us

相关标签:
4条回答
  • 2021-02-05 06:48

    It will display alert after clicking on the OK button.

    $( "#WaitingDialog").html("Message you want to display").dialog({
       modal: true,
       buttons: { 
        Ok: function() {
           alert("hello");
        }
    }});
    

    It will display alert after opening the modal

    $( "#WaitingDialog").html("Message you want to display").dialog({
        modal: true,
        buttons: { 
            open: function( event, ui ) {
                  alert('hello');
              }
        }});
    
    0 讨论(0)
  • 2021-02-05 06:54

    You can use this :

    $( ".selector" ).dialog({
      open: function( event, ui ) {}
    });
    

    or the event listener .on

    $( ".selector" ).on( "dialogopen", function( event, ui ) {} );
    

    More information in this page :

    http://api.jqueryui.com/dialog/#event-open

    0 讨论(0)
  • 2021-02-05 06:56

    You can also use the focus event Click here for documentation

    0 讨论(0)
  • 2021-02-05 06:59

    Try this:

    jsFiddle here

    HTML:

    <div id="dialogbox"></div>
    <input id="mybutt" type="button" value="Click Me">
    

    Javascript/jQuery:

    $("#dialogbox").dialog({
        autoOpen:false,
        modal:true,
        title: "Use of Open event",
        width:300,
        open: function( event, ui ) {
            alert('hello');
        }
    });
    
    $('#mybutt').click(function() {
        $('#dialogbox').html('<h2>Watch this</h2>An alert box should have opened');
        $('#dialogbox').dialog('open');
    });
    
    0 讨论(0)
提交回复
热议问题