$-----JavaScript in the role of dollar sign $

Source: Internet
Author: User

What is the dollar sign $ in JavaScript

1, the first can be used to represent variables, such as variable var s= ' asdsd ' or var $s = ' asdasd ';

2, in the regular expression, it can match the end:/sa$/.test (String)
Matching the SA in string string, such as string= ' 125sa ', string= ' 125sa21 ' does not match the regular expression is complex, here is simply to say.

3, due to the prototype.js (the framework of the foreigner, used to encapsulate some common functions, convenient operation) of the impact, now many people use $ to represent a function to find objects:
$=function (ID) {return (typeof (id) = = ' object ')? Id:document.getElementById (id);};
is actually a custom function, with $ just simple, in fact, with other characters is the same:
F=function (ID) {return (typeof (id) = = ' object ')? Id:document.getElementById (id);};
Where the parameter ID is an ID in an HTML document, such as <div id= ' SS ' ></div> then obj=$ (' SS ') is the object referenced by this id= ' SS '.


Convenient for frequent use of document.getElementById (ID) Writing convenience:

function $ (ID) {
return document.getElementById (ID);
}

Prototype.js inside the definition. Not JS itself.

5. Indicates what function to call directly

// 直接引用,jsp中一般写在head里面,或者是

<script src="你的jquery的路径"type="text/javascript"></script>// 然后直接把jquery代码写到<script>之前就可以了<script type="text/javascript">    // 使用 $(function(){}) 相当于 onload="某个方法"    $(function(){        // 这里写你要执行的代码吧    })</script>

$-----JavaScript in the role of dollar sign $

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.