The following is a brief introduction:
The first is the method of obtaining objects in js, which is relatively straightforward. If a page has multiple ids, you have to write such a long document.getElementBy("id ")
document.getElementBy( "id")
Abbreviation for document.getElementById
Personally, I recommend using the definition of document.getElementById in prototype:
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:
function $(objectId) {
if(document .getElementById && document.getElementById(objectId)) {
return document.getElementById(objectId);// W3C 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 one is to get the id in jquery The method
can be found in this article
http://www.jb51.net/article/27617.htm http://www.jb51.net/article/26702.htmStatement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn