Home > Web Front-end > JS Tutorial > JS FAQs (continuously updated)_javascript skills

JS FAQs (continuously updated)_javascript skills

WBOY
Release: 2016-05-16 17:26:27
Original
1075 people have browsed it
1. The meaning of $ symbol in JS
[Indicates variables] For example, variable var s='asdsd' or var $s='asdasd';
[Match the end, in regular expressions] /sa$/.test(string) matches sa in the string string. For example, string='125sa' matches, string='125sa21' does not match.
[Represents a function to find objects]
Copy code The code is as follows:

$=function (id) {

Copy code The code is as follows:

return (typeof (id)=='object') ?id:document.getElementById(id); };

is actually a custom function. It’s just simple to use $, but it’s the same with other characters,
Copy code The code is as follows:

f=function (id) {

Copy code The code is as follows:

return (typeof (id)=='object')?id:document.getElementById (id); };

You can also use the parameter id to be the id in the html document, such as
Copy code The code is as follows:



Then obj=$('ss') is The referenced object with id='ss' uses the $() method
The $() method is a convenient shorthand for the document.getElementById() method that is used too frequently in the DOM, just like this DOM method, this The method returns the element with the id passed in as the parameter. This is better than the method in DOM. You can pass multiple ids as arguments and $() returns an Array object with all required elements.
2. The meaning of the # symbol in JS
This #XXXX represents the id of a certain HTML element. This is based on the selector of css. In css, #xxx means the specified Element ID to find elements Generally, HTML elements define their id through the id attribute. For example,
Copy code The code is as follows:

...


The ID here is mydiv, used above The function is $("#mydiv"); and $(xxx) should be the jQuery code, used to return the element specified by xxx, where XXX is compatible with the css selector
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