Possible Duplicate:
What is the meaning of “$” sign in JavaScript

Now this must seem to be an easy and stupid question to ask but I must know why we use the dollar ($) symbol in jQuery and JavaScript. I always put a dollar in my scripts but I actuary don't know why.

例如:

$('#Text').click(function () {
  $('#Text').css('color', 'red')
});

这只是改变了文本的 colored颜色 ,当你点击它,但它证明了我的观点.

推荐答案

In JavaScript it has no special significance (no more than a or Q anyway). It is just an uninformative variable name.

In jQuery the variable is assigned a copy of the jQuery function. This function is heavily overloaded and means half a dozen different things depending on what arguments it is passed. In this particular example you are passing it a string that contains a selector, so the function means "Create a jQuery object containing the element with the id Text".

Jquery相关问答推荐

JQuery DateTimePicker-在 Select 中抓取星期几

当一个很长的活动增加标题时,满历js每周都会出现.这是一种让标题只出现一次的方法吗?

jQuery在localStorage时将类添加到正文

如果您的 Select 器对象无效,为什么 jQuery 不会炸弹?

如何从 jQuery 转到 React.js?

何时执行 $(document).ready 回调?

如何使用 jQuery 以编程方式触发对链接的点击?

为什么我们在 jQuery 中使用({ })?

jQuery scrollTop 在 Chrome 中不工作但在 Firefox 中工作

当ID包含方括号时按ID查找DOM元素?

javascript 正则表达式用于包含至少 8 个字符、1 个数字、1 个大写和 1 个小写的密码

模态窗口中的 Twitter Bootstrap Datepicker

从父 node 中删除所有子 node ?

使用 jquery 通过文本设置下拉值

jQuery: Select 所有具有自定义属性的元素

如何通过jQuery函数仅获取直接子元素

如何使用 jQuery 取消设置元素的 CSS 属性?

超时 jQuery 效果

使用 JQuery 的黄色淡入淡出效果

单击时平滑滚动到特定的 div