English 中文(简体)
jQuery UI modal dialog not blocking
原标题:

I am new to javascript and jQuery. I am trying to implement a modal dialog using jQuery UI widgets.

The modal dialog shows up correctly with OK and Cancel buttons, but the dialog( open ) function call does not seem to block and wait for an OK or Cancel click. For example, when I run the following code

.....on button click

  okToDelete = false; //a global variable
  $( deleteDialog ).dialog( open ); //this does not block but returns immediately
  alert(okToDelete == true ? "ok" : "false");

The alert box is displayed first and THEN the modal dialog shows up! okToDelete is a global variable I set to false when I enter the function and set to true in the OK button callback.

Here is my dialog init function

$("#deleteDialog").dialog({
        bgiframe: true,
        autoOpen: false,
        modal: true,
        overlay: {
            backgroundColor:  #000 ,
            opacity: 0.5
        },
        buttons: {
            Cancel: function() {
                $(this).dialog( close );

            },
            Ok: function() {
                $(this).dialog( close );
                okToDelete = true;
            }
        }
    });
问题回答

It is not meant to block . If you want to display the alert (I assume that s for testing) or call other functions after the dialog closes, if you to place it within the callback or the ok, cancel functions.

Check this out:
http://docs.jquery.com/UI/Dialog#event-close

The event close from the docs:
This event is triggered when the dialog is closed.
Code examples

Supply a callback function to handle the close event as an init option.

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

Bind to the close event by type: dialogclose.

$( .selector ).bind( dialogclose , function(event, ui) {
  ...
});




相关问题
How to start to create an application GUI using C#?

HI! I am new to C# and plan to use it for my application GUI. I am trying to make my GUI similar to SPSS:http://www.spss.com/images/08/statistics_screens/ez_rfm-big.jpg Is this easy in C#? Is there ...

Automatic height of edit box

My shoes application has three items stacked on top of each other (with a stack, of course), in order: A banner An edit box Two buttons in a flow What I want to do is have the banner stay at it s ...

Search by using the keyboard in a list/grid - algorithm

I need to implement a custom search in a grid and I would like to find some user interface guidelines that explain the standard way to implement it. I mean this kind of search that is initiated by ...

UI And TcpClient Issue in vb.net

I m having some problems with a small ircbot i m writing. Basically I connect to the server using a tcpclient in a seperate class, which also runs on its own thread. I want to display the server text ...

UI Convention: Shortcut key for application exit? [closed]

Is there a convention for the shortcut keys for application exit? Some applications uses Alt+X some others use Ctrl+ X and Ctrl+Q. Applications like FF and IE doesnot assign a shortcut at all. So is ...

热门标签