(4)事件处理——(5)为代码简洁做的快捷方式(Shortcuts for code brevity)
2013-10-11 15:03
309 查看
The $(document).ready()construct is actually calling the .ready()method on a jQuery object we've constructed from the documentDOM element. The $()function provides a shortcut for us as this is a common task. When we pass in a function as the argument, jQuery performs an implicit call to .ready(). For the same result as shown in the following code snippet:
We can also write the following code:
While this other syntax is shorter, the longer version makes code more descriptive about what it is doing. For this reason, we will use the longer syntax throughout this book.
$(document).ready()结构事实上是调用了我们从一个DOM元素创建的jquery对象的.ready()方法。由于这些相同的任务,$()函数为我们提供了一个快捷方式。当我们把一个函数作为参数传递进去的时候,jquery会隐式调用.ready()方法。正如下面的代码片段造成相同的结果:
我们以可以写下面的代码:
虽然另一种语法更加短,但是这个长的让更好的描述了他在做的事情。由于这个原因,我们将在整本书中使用长一些的语法。
$(document).ready(function() { // Our code here... });
We can also write the following code:
$(function() { // Our code here... });
While this other syntax is shorter, the longer version makes code more descriptive about what it is doing. For this reason, we will use the longer syntax throughout this book.
$(document).ready()结构事实上是调用了我们从一个DOM元素创建的jquery对象的.ready()方法。由于这些相同的任务,$()函数为我们提供了一个快捷方式。当我们把一个函数作为参数传递进去的时候,jquery会隐式调用.ready()方法。正如下面的代码片段造成相同的结果:
$(document).ready(function() { // Our code here... });
我们以可以写下面的代码:
$(function() { // Our code here... });
虽然另一种语法更加短,但是这个长的让更好的描述了他在做的事情。由于这个原因,我们将在整本书中使用长一些的语法。
相关文章推荐
- (4)事件处理——(5)为代码简洁做的快捷方式(Shortcuts for code brevity)
- 对象事件与处理程序代码进行关联的几种方式
- (4)事件处理——(3)代码执行的顺序(Timing of code execution)
- (4)事件处理——(3)代码执行的顺序(Timing of code execution)
- 如何把应用程序的快捷方式(shortcuts)添加到桌面——(开源项目apps-for-android中的AnyCut项目详解)
- win7重装后的一直有好123的快捷方式exe的处理方法。
- jQuery的实现原理的模拟代码 -3 事件处理
- IDEA 代码抛异常快捷方式
- cocos2dx中精灵点击事件处理的两种方式——Sprite和ImageView
- FOR 新手:一段Text Helper代码,用于文字处理:去掉HTML标记,以及字符串相减
- 用ACE的Reactor模式实现网络通讯时,ACE内部用WSAEventSelect函数把网络事件与一个事件对象关联起来,目的是为了后面用WaitForMultipleObjects函数统一处理。
- js 创建快捷方式的代码(fso)
- C#事件-预定义事件处理方式
- 纯代码处理键盘遮挡事件
- Android 处理事件的两种方式对比
- 从零开始学android<android事件的处理方式.二十四.>
- Java事件处理机制-事件监听器的四种实现方式
- 腾讯 QQ for Linux 的安装及 tar.gz版本QQ 建立快捷方式
- 是时候来了解android7了:shortcuts(快捷方式)
- [C#][SAMPLE][CODE][Control]TextBox和Validating事件的相关处理