开发者

jQuery dispatch event? How to

how can i dispatch an event on my window ready? For example in my code i've got:

开发者_JS百科
$("#info").click(function(){
// do stuff
});

I need to call this function the first time without have a click on #info, in the way // do stuff.


You could use the .trigger() method:

$('#info').trigger('click');

or simply:

$('#info').click();

which would be the same.


A better way might be to make a function that does the required stuff, then do $(document).ready(myFunc); and $("#info").click(myFunc);.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜