在下面的示例中,$()函数的作用是什么?
function test(){
var b=$('btn1');
eval(b);
}发布于 2010-01-30 18:36:48
这不是ECMAScript (JavaScript)的一部分。它只是一个由你的某个库定义的函数。通常是jQuery或PrototypeJS。
发布于 2010-01-30 18:37:34
JavaScript语言中不包含$()方法。它通常在jQuery和Prototype等JavaScript框架中定义为DOM选择器。
有趣的是,直到2009年12月,ECMAScript规范都在声明:
标识符中的任意位置都允许使用美元符号($)和下划线(_)。美元符号仅用于机械生成的代码。 (Source)
然而,这个“机械生成代码的美元符号”提示被从current ECMAScript specification (ECMA262-第5版/2009年12月)中删除了。
尽管如此,最初的问题可能指的是jQuery、Prototype等公司中流行的DOM选择器。下面是几个jQuery示例:
$('*'); /* This selector is a wild card method and will select all
elements in a document. */
$('#id'); /* This selector selects an element with the given ID. */
$('.class'); /* The class selector will gather all elements in the
document with the given class name. */
$('element'); /* This selector will collect all elements in a document with
the given tag name i.e. table, ul, li, a etc. */您可能想要查看以下文章以获取更多示例:
发布于 2010-01-30 18:37:10
我认为您正在处理的是一个框架。大多数框架都包含从选择器或dom对象生成自定义对象的$函数。
https://stackoverflow.com/questions/2167544
复制相似问题