问题描述
有人能解释一下jquery中$
和$()
之间的区别吗?
Could someone take the effort to explain me the difference between $
and $()
in jquery?
我知道$()
是$jQuery()
的简写形式,它接受任何DOM元素并将其转换为jQuery对象.
I know $()
is shorthand form of $jQuery()
which takes any DOM element and turns it into a jQuery object.
但是我不确定什么是$
,它与$()
有何不同.请赐教.
But what I am not sure of is what is $
and how different is it from $()
. Kindly enlighten me.
感谢堆,柴坦亚
推荐答案
$
是函数,可以称为-$()
.
$()
的行为在很大程度上取决于所提供的参数,尽管下面的所有示例都会返回一个jQuery
对象.它可以:
The behaviour of $()
varies immensely depending on the parameters supplied, although all examples below will return a jQuery
object. It can:
- 注册
document.ready
处理程序-$(myfunc)
- 充当选择器 -
- 构造元素-
$('<div>')
- 返回一个空对象-
$()
- register a
document.ready
handler -$(myfunc)
- act as a selector -
$('#myid')
- construct elements -
$('<div>')
- return an empty object -
$()
$
也是一个对象,其中包含各种实用程序功能$.each
,例如该对象的 properties .在这种情况下,这些功能就像 namespace 一样.
$
is also an object that contains various utility functions $.each
, etc as properties of that object. In this context, it acts like a namespace for those functions.
这篇关于jQuery中$和$()之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!