$(document.body)和$('body')JQuery之间的区别 [英] Difference between $(document.body) and $('body') JQuery

查看:262
本文介绍了$(document.body)和$('body')JQuery之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一名JQuery初学者,正在研究一些代码中的一些示例.

I am a JQuery beginner and while going through some examples in some codes found.

$(document.body)$('body')

谁能告诉我这两者之间有什么区别吗?

Could anyone tell me is there any difference between these two?

推荐答案

它们引用相同的元素,不同之处在于,当您说document.body时,您是将该元素直接传递给jQuery.另外,当您传递字符串'body'时, jQuery选择器引擎必须解释该字符串以找出哪个元素(s).

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.

如果您有兴趣,可以在 jQuery函数的文档中找到更多信息.

If you are interested, there is more information in the documentation for the jQuery function.

这篇关于$(document.body)和$('body')JQuery之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆