[英]difference between $ and $$
I used $
instead of document.getElementById()
in javascript and i don't know what is the use of $$
. 我在JavaScript中使用
$
代替了document.getElementById()
,我不知道$$
的用途是什么。 Can any one please tell me what is the use of $$
? 谁能告诉我
$$
的用途是什么?
Here is the code: 这是代码:
var link_object = $$('a[class="menu_item"]');
if (window.location.href.search('inident.do') >= 0) {
link_object.each(function (elem) {
if (elem.innerHTML == 'Create an Incident') {
elem.style.fontWeight = 'bold';
elem.style.color = 'black';
}
});
}
The single $ is usually a short name for jQuery object. 单个$通常是jQuery对象的简称。 The double $$ could be anything.
双$可以是任何东西。
In Angular, seems to designate a private identifier. 在Angular中,似乎指定了一个私有标识符。
You can do something like this when you hate your colleagues : 当您讨厌同事时,您可以执行以下操作:
$$$$($$$[$]);
$ is the selector in jquery. $是jquery中的选择器。 $$ doesn't have any specific meaning in jquery so you can use it in your own way.
$$在jquery中没有任何特定含义,因此您可以以自己的方式使用它。 like this
像这样
function $$(){
alert('hello');
}
$$();
There may be other libraries like jquery which use $ or may be use $$. 可能还有其他类似$ query的库,例如jquery。 since $ is valid symbol in javascript for variable and function names it is the best way to simplify the dom selection instead of using long document.getElementById() like functions.
由于$是javascript中变量和函数名称的有效符号,因此它是简化dom选择的最佳方法,而不是像函数一样使用long document.getElementById()。
contribution of Mr. Robg 罗布先生的贡献
In jQuery, $ is a function that takes different types arguments. 在jQuery中,$是一个接受不同类型参数的函数。 It will accept functions, arrays, objects (native and host), strings or nothing at all.
它将接受函数,数组,对象(本机和主机),字符串或什么都不做。 If it gets a string, it will work with a selector or HTML
如果获取字符串,它将与选择器或HTML一起使用
$$ doesn't have any particular meaning for jQuery. $$对jQuery没有任何特殊含义。 But if you are using some library who can conflict with jQuery, you can change the name of $ function to anything you want by using jQuery noConflict function;
但是,如果您使用的某个库可能与jQuery发生冲突,则可以使用jQuery noConflict函数将$函数的名称更改为所需的任何名称。
You should look for something like this early in your code 您应该在代码的早期寻找类似的东西
var $$ = jQuery.noConflict();
Are you sure this is jQuery ? 您确定这是jQuery吗? It looks like mootools .
它看起来像Mootools 。
In mootools, $$() is the element selector function. 在mootools中, $$()是元素选择器函数。 It works similar to $() in jQuery.
它的工作方式类似于jQuery中的$()。
$('id')
returns the element with id 'id'. 返回ID为'id'的元素。
$$('selector')
returns a collection of the elements corresponding to the selector passed. 返回与传递的选择器相对应的元素的集合。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.