开发者

Problem with delay()

My requirement is to execute some code after some amount of time..Here is my code but it开发者_JS百科 is not working, Might be some problem with my code..

$(document).ready(function()
{
 $.doTimeout(300,function() 
{
 $('xxxButton').trigger();
});
});


doTimeout isn't a function. You want:

$(function(){
    setTimeout(function(){
        $('xxxButton').trigger();
    }, 300);
});

$(function(){}); is a shortcut for $(document).ready(function(){}); btw


The trigger function in jQuery requires an argument to tell jQuery which event type you want to trigger. I'd guess that you have a button of some sort with an id attribute of xxxButton and you want to click it, if so, then you want:

$(document).ready(function() {
    $.doTimeout(300, function() {
        $('#xxxButton').click();
    });
});

You could also use $('#xxxButton').trigger('click') if you really want to use trigger.


Using setTimeout

$(document).ready(function()
{    
setTimeout( function() {
        $('xxxButton').trigger('click');
    }, 300 );

);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜