Home > Web Front-end > JS Tutorial > body text

Detailed explanation of $ symbol in js program

巴扎黑
Release: 2016-11-25 13:37:30
Original
1659 people have browsed it

The

$ symbol is a characteristic character representing variables in php, and it also has many functions in js.
1.1 is used to represent variables.
Example:
var str='hello world !';
var $str='hello world !';
1.2 In regular expressions, match the end.
1.3 Due to the influence of prototype.js (a framework used to encapsulate some commonly used functions for easy operation), $ is often used to represent a function that finds objects. In fact, it is a custom function. Using $ is just simple, unlike using other The characters are the same.
Example:
HTML code


JS code
$=function (id){
return (typeof (id)=='object')? Id : document .getElementById(id);
}
or
f=function (id){
return (typeof (id)=='object')? Id : document.getElementById(id);
}
Call function
obj=$ ('name');
obj=f('name');
The $() method is a shorthand for the document.getElementById() method that is used too frequently in HTML DOM. Just like this DOM method, this method returns The element whose id is passed as the parameter. But the $() method is better. It can accept multiple id parameters and return an Array object that meets all required elements.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template