JavaScript can define $ symbolic functions, which can be abbreviated or written with better compatibility.
The Code is as follows:
Function $ (id) {return document. getElementById (id );
The previous version of the browser is no problem, if you use an old browser, you can use the following function
The Code is as follows:
Function $ (objectId ){
If (document. getElementById & document. getElementById (objectId )){
// W3C DOM
Return document. getElementById (objectId );
}
Else if (document. all & document. all (objectId )){
// MSIE 4 DOM
Return document. all (objectId );
}
Else if (document. layers & document. layers [objectId]) {
// NN 4 DOM.. note: this won't find nested layers
Return document. layers [objectId];
}
Else {
Return false;
}
}
To implement $ instead of document. the effect of getElementById is simple, but it does not reference prototype, jquery, and other frameworks. getElementById, which can be used everywhere after being defined in a public JavaScript file.