这个JQuery指令做什么$(function(){...}) [英] What does this JQuery instruction do $(function(){...})

查看:125
本文介绍了这个JQuery指令做什么$(function(){...})的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近一直在学习JQuery,尽管我知道一些东西,但在一本书中却有一句我根本无法想象的:

I have been studying JQuery lately and, even though I know some stuff, there's this line in a book that I simply can't figure out:

$(
   function()
   {
      current_entry = -1;
   }
);

有没有人知道这一行是如何工作的,它是什么?

Does anyone know HOW this line works and WHAT it does?

它是一个像JQuery函数中的选择器一样的函数?

Is it something like a function as selector within the JQuery function?

作为Web开发食谱中使用的引用,第2章,第9节 - 使用键盘快捷键与网页互动(Pg 62)。

As a reference that line is used in the book Web Development Recipes, Chapter 2, Recipe 9 - Interacting with Web Pages Using Keyboard Shortcuts (Pg 62).

感谢您的帮助。

推荐答案

这是 document.ready 事件的简短形式。

It is short form of document.ready event. It is executed when DOM is ready.

以下所有三种语法都是等效的:

All three of the following syntaxes are equivalent:


  • $(document).ready(handler)

  • $()。ready(处理程序)(不建议这样做)

  • $ (handler)


传递给.ready()的处理程序必须在
DOM就绪,所以这通常是附加所有其他
事件处理程序并运行其他jQuery代码的最佳位置。当使用依赖于
的脚本在CSS样式属性的值上时,引用
脚本之前引用
外部样式表或嵌入样式元素很重要, jQuery api

这篇关于这个JQuery指令做什么$(function(){...})的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆