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 $