JavaScript 中$ 是什么含义

来源:百度知道 编辑:UC知道 时间:2024/06/15 07:13:03
JS中有这样一段代码:
...
var info = getInfo(DndElement);
parentElement.insertBefore($("DndVisualIndicator"),DndElement);
$("DndVisualIndicator").style.height = DndElement.offsetHeight;
$("DndVisualIndicator").style.width = DndElement.offsetWidth;
...
请问上面的语句中$代表什么含义??

js中$本身就是普通的字符,可用作变量,函数名,在ajax框架中常被用来定义为取代getElementById的函数.

看你这个程序应该就是getElementById
因为后面取style了

var $ = function(el){
return (typeof el == 'object')?el:document.getElementById(el);
};
var $A = function(el){
return (typeof el == 'object')?el:document.all(el); //IE Only && 仅IE支持
};
var $C = function(el){
return document.createElement(el);
};
var $N = function(el){
return (typeof el == 'string')?document.getElementsByTagName(el):null;
};

就是定义一函数,然后用的时候方便

字符型,与串长有关,取值范围:0~65535