“$”是什么?在jQuery或JavaScript中的符号意味着什么? [英] What does the "$" sign mean in jQuery or JavaScript?
问题描述
现在这似乎是一个简单而愚蠢的问题但我必须知道为什么我们在jQuery和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')
});
这只是在您单击时更改文本颜色,但它证明了我的观点。
This just changes the text colour when you click it, but it demonstrates my point.
推荐答案
在JavaScript中它没有特别的意义(不超过 a
或 Q
无论如何)。它只是一个无信息的变量名称。
In JavaScript it has no special significance (no more than a
or Q
anyway). It is just an uninformative variable name.
在jQuery中,为变量分配了 jQuery
函数的副本。这个函数严重超载,意味着六个不同的东西,这取决于它传递的参数。在这个特定的例子中,您传递的是一个包含选择器的字符串,因此该函数意味着创建一个包含id为 Text 的元素的jQuery对象。
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或JavaScript中的符号意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!