- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
嘿,我刚刚为我的 JS 和 jQuery 实践编写了另一个基本脚本,当我意识到这实际上是由什么组成时,我只是抽出 goold ol' 文档就绪事件,我想知道我是否对不对:
这是为 jQuery 准备的文档:
$(document).ready(function(){});
现在,美元符号是 jQuery 的简写,它调用 jQuery 库,因此我们可以进行 jQuery 语句和调用,对吗?
(文档)是一个选择器,它指的是 DOM 的“最高”部分(除了 Window?)。
.ready 是在 DOM 完全加载时发生的 Action 。现在,“DOM”已完全加载,这种情况下的 DOM 是否指的是被选中的内容?那么,如果选择的是 body 而不是 document,脚本会在加载之前执行吗?
(function(){});
这部分让我有点困惑。
我知道一旦我们的文档加载完毕,它就会运行我们的脚本。换句话说,它会运行我们的功能吗?我们的整个脚本是否被认为是一个函数?而且,它真的只是一个大的 JavaScript 语句,对吗?因为它以分号结尾。另外,为什么我们的脚本通常位于大括号之间,而不是函数的括号之间?有什么区别?
非常感谢,抱歉 n00by 的问题,我只是好奇! xD
最佳答案
哇,这么多问题一个回答:)
Now, the dollar sign is shorthand for jQuery, which calls the jQuery library, so we can make jQuery statements and calls, correct?
是的,$
和 jQuery
引用同一个对象。取自 jQuery 的来源:
// Expose jQuery to the global object
window.jQuery = window.$ = jQuery;
window
是全局对象。添加到其中的任何内容都可以在全局范围内使用,因此您可以将其称为 window.$
, 或者只是 $
例如。
The (document) is a selector that is referring to the "highest" piece of the DOM (other than Window?).
document
不是选择器,而是 DOM object指的是 DOM 中最顶层的节点。它具有其他属性,例如 document.domain
等。它的一个 child 是 <html>
元素。
.ready is an action that occurs when the DOM is fully loaded. Now, the "DOM" being fully loaded, does the DOM in this case refer to what's being selected?
是的,DOM指的是我们通常在jQuery选择器中选择的项。更具体地说,它是页面在内存中的表示。 ready
为不同的浏览器使用一系列事件来确定 DOM 何时加载。
So if, body was selected instead of document, would the script executed before the loaded?
目前 jQuery 的源代码不关心当您调用 ready
时传入的选择器是什么。 .这是就绪函数:
ready: function( fn ) {
// Attach the listeners
jQuery.bindReady();
// If the DOM is already ready
if ( jQuery.isReady ) {
// Execute the function immediately
fn.call( document, jQuery );
// Otherwise, remember the function for later
} else if ( readyList ) {
// Add the function to the wait list
readyList.push( fn );
}
return this;
},
因为它不关心传入的是什么选择器,所以您也可以传递它 body
,什么都没有,或者你想要的任何东西。
$({
an: 'object',
that: 'has',
nothing: 'to',
'do': 'with',
ready: 'event'
}).ready(function() { .. });
它仍然有效。
(function(){});
This part gets me a little confused.
I know that once our document has loaded, then it will run our script. In other words, it will run our function right?
是的,当 DOM 就绪时,将执行此函数以及您与 ready 事件绑定(bind)的每个函数。
Is our whole script being thought of as a function?
不,不是整个脚本。只有依赖于 DOM 的项目。有些事情需要在发现时进行处理。想想 jQuery 库本身。它在处理之前不会等待任何 DOM 就绪事件。如果您编写 JavaScript 语句,它将按照找到的顺序进行处理,除非它是像您传递给 ready(..)
的那样的回调函数。 .因此,无论 DOM 是否已加载,下面的代码都会立即执行并发出“hello”提示。
<script>
function hello() { alert("hello"); }
hello();
</script>
And, it's really just one big JavaScript statement, correct?
不是真的。你可以随心所欲地模块化你的 JavaScript。例如,您可以拥有类似于类、对象、可重复使用的小部件、架构模式(例如 MVC)等等。
Because it ends in a semi-colon.
分号与何时执行某事无关。我写得很好。
<script>
alert("Hello"), alert("World")
</script>
这将起作用并按顺序提醒这两个词,并且没有分号。
Also, why does our script generally go between the braces, and not the parentheses of the function? What is the difference?
这就是在 JavaScript 和其他几种语言中定义函数的方式。复习你的基本技能,以便更好地理解。不要将其称为脚本,因为它只会混淆问题。它只是一个函数,里面有一些语句。
关于javascript - 了解文档就绪事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3364255/
我有一个 .sln 文件,里面有几个项目。为了简单起见,让我们称它们为... 项目A 项目B 项目C ...其中 A 是引用 B 和 C 的主要项目。我的目标是更新我的构建脚本,为 ProjectA
我安装了 Magento,我想知道如何生成完整的 API 文档,例如 http://docs.magentocommerce.com/ 上的文档是使用 phpdoc 生成的。 Magento 中是否包
我通常使用jetbrains family ide。在为函数创建文档时非常有用,只需输入 /** 如何在创建文档时创建自定义标签,例如@date标签。 最佳答案 JavaScript、Java: st
我正在尝试使用 jOpenDocument library创建文档。我已经执行了创建电子表格的示例 - 代码编译并运行正常,但当我尝试使用 Excel Office 2012 或 Google Doc
如标题。 有没有介绍HTML DOM构造的图片? 最佳答案 DOM(文档 对象模型)从文档 节点开始。它被称为“根节点”。 观察下面的树(括号中对应的nodeType): [HTMLDocument]
我喜欢 ColdFusion Builder。但我不喜欢帮助只有 CF9 文档。有什么方法可以将其更改为拥有 ColdFusion 8 文档? 最佳答案 http://livedocs.adobe.c
这个问题在这里已经有了答案: What is the consequence of this bit of javascript? (4 个答案) 关闭 9 年前。 我看到一些 jQuery 脚本嵌
我有一个 XML 文件,其中包含需要在 Word 文档中填充的数据。 我需要找到一种方法来定义一个模板,该模板可用作从 XML 文件填充数据并创建输出文档的基线。 我相信有两种方法可以做到这一点。 创
我正在尝试查找有关如何使用 AVAudioEngine 的详细文档。有谁知道我在哪里可以找到它? 我找到了这个,但与文档丰富的 UI 内容相比,它似乎非常简陋。 https://developer.a
我对 Tensorflow 文档越来越感到恼火和沮丧。我在谷歌上搜索了有关 的文档 tf.reshape 我被定向到一个通用页面,例如 here 。我想查看 tf.reshape 的详细信息,而不是整
我正在学习本教程:http://moxleystratton.com/clojure/clojure-tutorial-for-the-non-lisp-programmer 然后遇到了这个片段: u
如何在 swagger 中为对象数组编写文档。这是我的代码,但我不知道如何访问对象数组中的数据。 { "first_name":"Sam", "last_name":"Smith",
是否有针对 Javascript 的 JavaDocs 之类的东西?当我在 netbeans IDE 中按 ctrl+space 时 写javascript,指定对象的javascript文档就出来了
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 5 年前。
我需要 JavaScript 中的 heredoc 之类的东西。你对此有什么想法吗?我需要跨浏览器功能。 我发现了这个: heredoc = '\ \ \ zzz\ \
WSDL 文档是包含一系列的,可描述某个 web service 的定义的,简单的 XML 文档 WSDL 文档结构 WSDL 文档用下表这些主要的元素来描述某个 web service 的
是否有 ocropus 的文档? 我正在寻找对以下功能的解释: make_SegmentPageByRAST(): segment() RegionExtractor(): setPageLines(
这个问题在这里已经有了答案: Understanding events and event handlers in C# (13 个回答) 4年前关闭。 我正在使用 NRECO 和 ffmpeg 对视
我正在尝试访问工作服务器以与名为 Spotfire 的应用程序一起使用。我的同事把这个传给我,现在已经休息了几个星期,我对他的建议有意见。 实际上,当我通过 localhost 运行我的 Web 应用
Elm 文档没有给出示例用法,因此很难理解类型规范的含义。在几个地方,我看到“a”用作参数标识符,例如 Platform.Cmd : map : (a -> msg) -> Cmd a -> Cmd
我是一名优秀的程序员,十分优秀!