How to Delay automatic opening of Modal Dialog box window in JQuery 1.5.x?

穿精又带淫゛_ 提交于 2020-01-04 08:23:14

问题


The following dialog box works nicely when clicked upon:

<a href="#" onclick="jQuery('#dialogX').dialog('open');
             return false"><? echo __("Under Construction")?></a>

The javascript sitting at the bottom of the html triggers the action:

jQuery("#dialogX").dialog({bgiframe: true, autoOpen: false, modal: true});

Now, what I would wish, is to have the dialog popup after say 2 seconds (insterad of immediately). I saw the option autoOpen and when setting the value to 2000 instead of false, that helas dit not work: it opens immediately. What am I missing?

Thanks very much for your hints and wish you a nice weekend.


回答1:


You can use

var timeoutID = window.setTimeout(func, delay, [param1, param2, ...]);
var timeoutID = window.setTimeout(code, delay);

from https://developer.mozilla.org/en/DOM/window.setTimeout It executes a code snippet or a function after specified delay.

So

setTimeout(function(){ showDialog() }, 2000);

should solve your problem.

Also have a look at the .delay( n ) method. http://api.jquery.com/delay/

$('.notice').fadeIn().delay(2000).fadeOut('slow'); 


来源:https://stackoverflow.com/questions/5603526/how-to-delay-automatic-opening-of-modal-dialog-box-window-in-jquery-1-5-x

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