当前位置: 首页 > 图文教程 > 网络编程 > Javascript > js程序中美元符号$是什么

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 js程序中美元符号$是什么


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 336 ::
收藏到网摘: n/a

$符号在php中是表示变量的特征字符, 在js中它也有很多作用, 一般我们用来命名一个函数名称,获取id的 1、首先可以用来表示变量,
比如变量 var s='asdsd'或var $s='asdasd';
2、在正则表达式中,它可以匹配结尾
/sa$/.test(string)
匹配string字符串中的sa,比如string='125sa'则匹配,string='125sa21'则不匹配
正则表达式很复杂,这里只是简单的说说。
3、由于受prototype.js(老外写的框架,用于将一些常用的函数封装,方便操作)的影响,
现在很多人都用 $来表示一个查找对象的函数,
$=function (id) { return (typeof (id)=='object')?id:document.getElementById(id); };
其实就是一个自定义函数,用$只是简单,其实用其它字符也是一样的,
f=function (id) { return (typeof (id)=='object')?id:document.getElementById(id); };也可以
其中参数id是html文档中的id,
比如<div id='ss'></div>
则obj=$('ss')就是引用的这个id='ss'的对象