返回值:jQueryload(handler(eventObject))
Bind an event handler to the "load" JavaScript event.
-
1.0 新增load(handler(eventObject))
handler(eventObject) (Function) A function to execute when the event is triggered. -
1.4.3 新增load([eventData], handler(eventObject))
eventData (Object) 可选参数,将要传递给事件处理函数的数据映射。handler(eventObject) (Function) 每当事件触发时执行的函数。
This method is a shortcut for .bind('load', handler)
.
The load
event is sent to an element when it and all sub-elements have been completely loaded. This event can be sent to any element
associated with a URL: images, scripts, frames, iframes, and the window
object.
It is possible that the load event will not be triggered if the image is loaded from the browser cache. To account for this possibility, we can use a special load event that fires immediately if the image is ready.
event.special.load
is currently available as a plugin.
For example, consider a page with a simple image:
<img src="book.png" alt="Book" id="book" />
The event handler can be bound to the image:
$('#book').load(function() { // Handler for .load() called. });
As soon as the image has been loaded, the handler is called.
In general, it is not necessary to wait for all images to be fully loaded. If code can be executed earlier, it is usually
best to place it in a handler sent to the .ready()
method.
The Ajax module also has a method named
.load()
. Which one is fired depends on the set of arguments passed.
示例:
Run a function when the page is fully loaded including graphics.
jQuery 代码:
$(window).load(function () {
// run code
});
示例:
Add the class bigImg to all images with height greater then 100 upon each image load.
jQuery 代码:
$('img.userIcon').load(function(){
if($(this).height() > 100) {
$(this).addClass('bigImg');
}
});