JavaScript "while" loop without freezing the browser?

I am trying to defer the default action by clicking on the link until the user clicks β€œyes” or β€œno” to confirm. The problem is that the while loop freezes the browser (and doesn’t even display a dialog, although "open" first opens):

$(".remove").click(function() {
  $("#dialog").dialog("open");

  while (1) {
    // Count sheep
  }
});

Obviously, β€œ1” exists only for testing purposes. In the end, I want him to check the variable set in the dialog box. For now, though I want to know how I can use a loop like this to delay the default click click action.

Thank,

Michael

+5
source share
6 answers

. . , .

.

+4

- window.setInterval while, .

, , . EDIT: jQuery, . :

$("#dialog").dialog("open", function() {
    // do your stuff for when they click OK
});
+4

setTimeout(FunctionHere, 3000);

Edit: , , jQuery.delay() , -.

+3

, click.

$(".remove").click(function(event) {
  event.preventDefault();
  $("#dialog").dialog("open");

  ....
});
+1

:

  • "while"
  • , , , .
  • , , jQuery UI, , .

    $('form').dialog({
        autoOpen: true,
        buttons: {
            "Yes": onRequestSubmit, // function defined elsewhere
            "No": function () { $(this).dialog("close"); } // function defined here
        },
        modal: true
    });
    
+1

... ?

setTimeout() , - ( , ). 10 ( ).

.NET.NET javascript. .

:

, , , , , - . , , #, C ++.

, , - HTML- .

<FORM NAME='dingoSam'>
 <INPUT TYPE='hidden' onChange='changed()' NAME='bingoSem'/>
</FORM>

, , dingoSam.bingoSem, .

, , javascript - . , , javascript, .

+1

All Articles