i want to call a jquery function on load of the page
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" (ie, 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.
链接地址: http://www.djcxy.com/p/71236.html上一篇: Javascript函数适用于回发,但不适合页面加载
下一篇: 我想在页面加载时调用jquery函数