$(document.body)和$('body')之间的区别 [英] Difference between $(document.body) and $('body')
问题描述
我是jQuery初学者,在浏览一些代码示例时,我发现:
$(document.body)
和 $('body')
这两个之间是否有区别?
它们引用相同的元素,不同之处在于,当您说 document.body
时您将元素直接传递给jQuery。另外,当您传递字符串'body'
时, jQuery选择器引擎必须解释该字符串以弄清楚它所指的是什么元素。
实际上,任一个都可以完成工作。
如果您有兴趣,可以在 jQuery函数的文档中找到更多信息。 / p>
I am a jQuery beginner and while going through some code examples I found:
$(document.body)
and $('body')
Is there any difference between these two?
They refer to the same element, the difference is that when you say document.body
you are passing the element directly to jQuery. Alternatively, when you pass the string 'body'
, the jQuery selector engine has to interpret the string to figure out what element(s) it refers to.
In practice either will get the job done.
If you are interested, there is more information in the documentation for the jQuery function.
这篇关于$(document.body)和$('body')之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!