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

查看:19
本文介绍了何时/为什么给变量加上“$"前缀什么时候使用 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天全站免登陆