返回值:jQueryready(fn)

概述

当DOM载入就绪可以查询及操纵时绑定一个要执行的函数。

这是事件模块中最重要的一个函数,因为它可以极大地提高web应用程序的响应速度。

简单地说,这个方法纯粹是对向window.load事件注册事件的替代方法。通过使用这个方法,可以在DOM载入就绪能够读取并操纵时立即调用你所绑定的函数,而99.99%的JavaScript函数都需要在那一刻执行。

有一个参数--对jQuery函数的引用--会传递到这个ready事件处理函数中。可以给这个参数任意起一个名字,并因此可以不再担心命名冲突而放心地使用$别名。

请确保在 <body> 元素的onload事件中没有注册函数,否则不会触发$(document).ready()事件。

可以在同一个页面中无限次地使用$(document).ready()事件。其中注册的函数会按照(代码中的)先后顺序依次执行。

参数

fnFunction

要在DOM就绪时执行的函数

示例

描述:

在DOM加载完成时运行的代码,可以这样写:

jQuery 代码:
$(document).ready(function(){
  // 在这里写你的代码...
});

描述:

使用 $(document).ready() 的简写,同时内部的 jQuery 代码依然使用 $ 作为别名,而不管全局的 $ 为何。

jQuery 代码:
jQuery(function($) {
  // 你可以在这里继续使用$作为别名...
});

目录 索引

输入要查找的关键字:

#id*.class:animated:button:checkbox:checked:contains:disabled:empty:enabled:eq:even:file:first-child:first:gt:has:header:hidden:hidden:image:input:last-child:last:lt:not:nth-child:odd:only-child:parent:password:radio:reset:selected:submit:text:visible[attrSel1][attrSel2][attrSelN][attribute!=value][attribute$=value][attribute*=value][attribute=value][attribute][attributeadd(expr, [context])addClass(class)addClass(function(index, class))after(content)after(function)ajaxComplete(callback)ajaxError(callback)ajaxSend(callback)ajaxStart(callback)ajaxStop(callback)ajaxSuccess(callback)ancestor descendantandSelf()animate(param,[dur],[e],[fn])animate(params, options)append(content)append(function(index, html))appendTo(content)attr(key, fn)attr(key, value)attr(name)attr(properties)before(content)before(function)bind(type, [data], fn)blur()blur(fn)change()change(fn)children([expr])clearQueue([queueName])click()click(fn)clone()clone(true)closest([expr])contents()contextcss(name)css(name, function(index, value))css(name, value)css(properties)data([name])data(name, value)data(obj)dblclick()dblclick(fn)delay(duration, [queueName])dequeue(name)detach([expr])die([type], [fn])each(callback)elementempty()end()eq(index)error()error(fn)fadeIn(speed, [callback])fadeOut(speed, [callback])fadeTo(speed, opacity, [fn])filter(expr)filter(fn)find(expr)first()focus()focus(fn)focusin( [fn] )focusout( [fn] )get()get(index)has(expr)hasClass(class)height()height(val)hide()hide(speed, [callback])hover(over, out)html()html(function(index, html))html(val)index(subject)innerHeight()innerWidth()insertAfter(content)insertBefore(content)is(expr)jQuery()jQuery(callback)jQuery(elements)jQuery(expr, [context])jQuery(html, [ownerDoc])jQuery(html, props)jQuery.ajax([options])jQuery.ajaxSetup([options])jQuery.boxModeljQuery.browser.versionjQuery.browserjQuery.contains(container, contained)jQuery.data([element], [key])jQuery.data(element, key, val)jQuery.each(object, [callback])jQuery.error(message)jQuery.extend([d],tgt,obj1,[objN])jQuery.extend(object)jQuery.fn.extend(object)jQuery.fx.offjQuery.get(url, [data], [fn], [type])jQuery.getJSON(url, [data], [fn])jQuery.getScript(url, [callback])jQuery.grep(array, fn, [invert])jQuery.inArray(value, array)jQuery.isArray(obj)jQuery.isEmptyObject(obj)jQuery.isFunction(obj)jQuery.isPlainObject(obj)jQuery.makeArray(obj)jQuery.map(array, callback)jQuery.merge(first, second)jQuery.noConflict()jQuery.noConflict(extreme)jQuery.noopjQuery.param(obj, [traditional])jQuery.parseJSON(json)jQuery.post(url, [data], [fn], [type])jQuery.proxy(function, scope)jQuery.supportjQuery.toArray()jQuery.trim(str)jQuery.unique(array)keydown()keydown(fn)keypress()keypress(fn)keyup()keyup(fn)last()lengthlive(type, [data], fn)load(url, [data], [callback])map(callback)mousedown(fn)mousemove(fn)mouseout(fn)mouseover(fn)mouseup(fn)next([expr])nextAll([expr])nextUntil([expr])not(expr)offset(coordinates)offsetParent()offsetone(type, [data], fn)outerHeight(options)outerWidth(options)parent > childparent([expr])parents([expr])parentsUntil([expr])position()prepend(content)prepend(function(index, html))prependTo(content)prev + nextprev ~ siblingsprev([expr])prevAll([expr])prevUntil([expr])queue(name ,callback)queue(name)queue(name, queue)ready(fn)remove([expr])removeAttr(name)removeClass(class | fn])removeClass(class)removeData(name)replaceAll(selector)replaceWith(content)resize(fn)scroll(fn)scrollLeft()scrollLeft(val)scrollTop()scrollTop(val)select()select(fn)selector1,selector2,selectorNselectorserialize()serializeArray()show()show(speed, [callback])siblings([expr])size()slice(start, [end])slideDown(speed, [callback])slideToggle(speed, [callback])slideUp(speed, [callback])stop([clearQueue], [gotoEnd])submit()submit(fn)text()text(function(index, text))text(val)toggle()toggle(fn, fn2, [fn3, fn4, ...])toggle(speed, [callback])toggle(switch)toggleClass(class)toggleClass(class, switch)toggleClass(function(index, class), [switch])trigger(type, [data])triggerHandler(type, [data])unbind([type], [data])unload(fn)unwrap()val()val(array)val(function(index, value))val(val)width()width(val)wrap(elem)wrap(fn)wrap(html)wrapAll(elem)wrapAll(html)wrapInner(elem)wrapInner(fn)wrapInner(html)
#id*.class:animated:button:checkbox:checked:contains:disabled:empty:enabled:eq:even:file:first-child:first:gt:has:header:hidden:hidden:image:input:last-child:last:lt:not:nth-child:odd:only-child:parent:password:radio:reset:selected:submit:text:visible[attrSel1][attrSel2][attrSelN][attribute!=value][attribute$=value][attribute*=value][attribute=value][attribute][attributeadd(expr, [context])addClass(class)addClass(function(index, class))after(content)after(function)ajaxComplete(callback)ajaxError(callback)ajaxSend(callback)ajaxStart(callback)ajaxStop(callback)ajaxSuccess(callback)ancestor descendantandSelf()animate(param,[dur],[e],[fn])animate(params, options)append(content)append(function(index, html))appendTo(content)attr(key, fn)attr(key, value)attr(name)attr(properties)before(content)before(function)bind(type, [data], fn)blur()blur(fn)change()change(fn)children([expr])clearQueue([queueName])click()click(fn)clone()clone(true)closest([expr])contents()contextcss(name)css(name, function(index, value))css(name, value)css(properties)data([name])data(name, value)data(obj)dblclick()dblclick(fn)delay(duration, [queueName])dequeue(name)detach([expr])die([type], [fn])each(callback)elementempty()end()eq(index)error()error(fn)fadeIn(speed, [callback])fadeOut(speed, [callback])fadeTo(speed, opacity, [fn])filter(expr)filter(fn)find(expr)first()focus()focus(fn)focusin( [fn] )focusout( [fn] )get()get(index)has(expr)hasClass(class)height()height(val)hide()hide(speed, [callback])hover(over, out)html()html(function(index, html))html(val)index(subject)innerHeight()innerWidth()insertAfter(content)insertBefore(content)is(expr)jQuery()jQuery(callback)jQuery(elements)jQuery(expr, [context])jQuery(html, [ownerDoc])jQuery(html, props)jQuery.ajax([options])jQuery.ajaxSetup([options])jQuery.boxModeljQuery.browser.versionjQuery.browserjQuery.contains(container, contained)jQuery.data([element], [key])jQuery.data(element, key, val)jQuery.each(object, [callback])jQuery.error(message)jQuery.extend([d],tgt,obj1,[objN])jQuery.extend(object)jQuery.fn.extend(object)jQuery.fx.offjQuery.get(url, [data], [fn], [type])jQuery.getJSON(url, [data], [fn])jQuery.getScript(url, [callback])jQuery.grep(array, fn, [invert])jQuery.inArray(value, array)jQuery.isArray(obj)jQuery.isEmptyObject(obj)jQuery.isFunction(obj)jQuery.isPlainObject(obj)jQuery.makeArray(obj)jQuery.map(array, callback)jQuery.merge(first, second)jQuery.noConflict()jQuery.noConflict(extreme)jQuery.noopjQuery.param(obj, [traditional])jQuery.parseJSON(json)jQuery.post(url, [data], [fn], [type])jQuery.proxy(function, scope)jQuery.supportjQuery.toArray()jQuery.trim(str)jQuery.unique(array)keydown()keydown(fn)keypress()keypress(fn)keyup()keyup(fn)last()lengthlive(type, [data], fn)load(url, [data], [callback])map(callback)mousedown(fn)mousemove(fn)mouseout(fn)mouseover(fn)mouseup(fn)next([expr])nextAll([expr])nextUntil([expr])not(expr)offset(coordinates)offsetParent()offsetone(type, [data], fn)outerHeight(options)outerWidth(options)parent > childparent([expr])parents([expr])parentsUntil([expr])position()prepend(content)prepend(function(index, html))prependTo(content)prev + nextprev ~ siblingsprev([expr])prevAll([expr])prevUntil([expr])queue(name ,callback)queue(name)queue(name, queue)ready(fn)remove([expr])removeAttr(name)removeClass(class | fn])removeClass(class)removeData(name)replaceAll(selector)replaceWith(content)resize(fn)scroll(fn)scrollLeft()scrollLeft(val)scrollTop()scrollTop(val)select()select(fn)selector1,selector2,selectorNselectorserialize()serializeArray()show()show(speed, [callback])siblings([expr])size()slice(start, [end])slideDown(speed, [callback])slideToggle(speed, [callback])slideUp(speed, [callback])stop([clearQueue], [gotoEnd])submit()submit(fn)text()text(function(index, text))text(val)toggle()toggle(fn, fn2, [fn3, fn4, ...])toggle(speed, [callback])toggle(switch)toggleClass(class)toggleClass(class, switch)toggleClass(function(index, class), [switch])trigger(type, [data])triggerHandler(type, [data])unbind([type], [data])unload(fn)unwrap()val()val(array)val(function(index, value))val(val)width()width(val)wrap(elem)wrap(fn)wrap(html)wrapAll(elem)wrapAll(html)wrapInner(elem)wrapInner(fn)wrapInner(html)