zoukankan      html  css  js  c++  java
  • (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...
    });
    虽然另一种语法更加短,但是这个长的让更好的描述了他在做的事情。由于这个原因,我们将在整本书中使用长一些的语法。
  • 相关阅读:
    Mybatis(4) 映射文件-参数处理
    Mybatis(3) 映射文件-增删改查
    Mabatis(2) 全局配置文件
    Mybatis(1) 创建Mybatis HelloWorld
    过滤器和拦截器之间的区别
    Redis(3) 配置文件 redis.conf
    Redis(2) 数据类型
    Redis(1) 初识Redis
    ActiveMQ(4) ActiveMQ JDBC 持久化 Mysql 数据库
    8.字典
  • 原文地址:https://www.cnblogs.com/phisy/p/3363434.html
Copyright © 2011-2022 走看看