(4)事件处理——(5)为代码简洁做的快捷方式(Shortcuts for code brevity)

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:
$(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...
});
虽然另一种语法更加短,但是这个长的让更好的描述了他在做的事情。由于这个原因,我们将在整本书中使用长一些的语法。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值