开发者

jQuery dispatch event? How to

开发者 https://www.devze.com 2023-01-28 01:18 出处:网络
how can i dispatch an event on my window ready? For example in my code i\'ve got:开发者_JS百科 $(\"#info\").click(function(){

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

精彩评论

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

关注公众号