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

Javascript
Add a Table to a Word Document
Add Formatted Text to a Word Document
用jscript实现新建word文档
用jscript实现新建和保存一个word文档
Open and Print a Word Document
Use Word to Search for Files
Convert Seconds To Hours
Sample script that deletes a SQL Server database
Sample script that displays all of the users in a given SQL Server DB
firefox中用javascript实现鼠标位置的定位
div+css实现鼠标放上去,背景跟图片都会变化。
Locate a File Using a File Open Dialog Box
Save a File Using a File Save Dialog Box
用jscript实现列出安装的软件列表
List the Stored Procedures in a SQL Server database
Display SQL Server Login Mode
Display SQL Server Version Information
List all the Databases on a SQL Server
用jscript启动sqlserver
Stop SQL Server

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 337 ::
收藏到网摘: 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'的对象