Home >Web Front-end >JS Tutorial >What is the dollar sign $ in js program_javascript skills

What is the dollar sign $ in js program_javascript skills

WBOY
WBOYOriginal
2016-05-16 19:03:561914browse

1. First of all, it can be used to represent variables,
For example, variable var s='asdsd' or var $s='asdasd';
2. In regular expressions, it can match the ending
/sa$ /.test(string)
Matches sa in the string string. For example, string='125sa' matches, string='125sa21' does not match.
Regular expressions are very complicated, here is just a brief explanation.
3. Due to the influence of prototype.js (a framework written by foreigners, used to encapsulate some commonly used functions for easy operation),
many people now use $ to represent a function that finds objects,
$=function (id) { return (typeof (id)=='object')?id:document.getElementById(id); };

is actually a custom function, using $ is just simple, In fact, the same applies to other characters,

f=function (id) { return (typeof (id)=='object')?id:document.getElementById(id); }; or
The parameter id is the id in the html document,

For example,



then obj=$('ss') is the referenced object with id='ss'
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn