开发者

i want to call a jquery function on load of the page

开发者_如何学Python

I want to call a jquery function on load of the page. There is also another Javascript getting called onload of the body tag.


You can do it like this:

$(function() {
  //do something
});

Or if you already have the function, like this:

function myFunction() {
  //do something
}

You can call it like this:

$(myFunction);

Both of the above are equivalent to $(document).ready(function);, they're just shortcuts.


No problem - they won't conflict with each other:

$(window).load(function() {...});

or...

$(document).ready(function() {...});

Use the second one if you don't need to wait for images and other external dependencies. It simply waits for the DOM to be "ready" (i.e., completely constructed).


Here's some good introductory reading on the subject, by the way.


There is a jQquery handler called .ready() that will do what you want. It executes with the DOM is ready. See also Use Onload or ready? for a discussion about the differences between ready and onload.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜