Copy Code code as follows:
function $ (ID) {return document.getElementById (ID);
The above is not a problem for the new version of the browser, if you use the old browser, you can use the following function
Copy Code code as follows:
function $ (objectId) {
if (document.getElementById && document.getElementById (objectId)) {
The Consortium 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 the $ Instead of document.getElementById, the effect is simple, but for frameworks that do not reference prototype and jquery, each write document.getElementById is avoided, and can be used everywhere after a common JavaScript file is defined Out.