何时/为什么用“$”引用变量前缀什么时候使用jQuery? [英] When/why to prefix variables with "$" when using jQuery?

查看:254
本文介绍了何时/为什么用“$”引用变量前缀什么时候使用jQuery?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

为什么javascript变量以美元符号开头?

我看到人们在使用jQuery时在变量前面使用美元符号。这背后有什么理由吗?我是缺少一些基本的东西,还是只是一种常见的做法?

I see people using the dollar sign in front of variables when using jQuery. Is there any reason behind this? I'm I missing something basic or is it just a common practice?

推荐答案

这是对jQuery包装对象的常见引用。它使得阅读代码更容易知道哪些变量是jQuery包装的。

It's a common reference to a jQuery wrapped object. It makes reading the code easier to know which variables are jQuery wrapped.

//Item has been "cached" for later use in the script as a jQuery object.
var $item = $(this);

这篇关于何时/为什么用“$”引用变量前缀什么时候使用jQuery?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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