The following is a brief introduction:
The first is JS to get the object of the method, more direct, if a page has more than one ID, each time to write so long Document.getelementby ("id")
Copy Code code as follows:
Document.getelementby ("id")
the shorthand method of document.getElementById
Personal comparison recommends the definition of document.getElementById in prototype:
Copy Code code as follows:
function $ ()
{
var elements = new Array ();
for (var i = 0; i < arguments.length; i++)
{
var element = Arguments[i];
if (typeof element = = ' String ')
element = document.getElementById (element);
if (arguments.length = 1)
return element;
Elements.push (Element);
}
return elements;
}
You can also use the following code to define:
Copy Code code as follows:
function $ (objectId) {
if (document.getElementById && document.getElementById (objectId)) {
return document.getElementById (OBJECTID);//The Consortium DOM
else if (document.all && document.all (objectId)) {
return document.all (OBJECTID);//MSIE 4 DOM
else if (document.layers && Document.layers[objectid]) {
Return document.layers[objectid];//NN 4 DOM. Note:this won ' t find nested layers
} else {
return false;
}
}
the second is the way to get IDs in jquery.
can refer to this article specifically
Http://www.jb51.net/article/27617.htm
Http://www.jb51.net/article/26702.htm