getElementByClass in Javascript - 两种代码
/* getElementByClass
/**********************/
var allHTMLTags = new Array();
function getElementByClass(theClass)
{
var allHTMLTags=document.getElementsByTagName('*');
for (i=0; i
if (allHTMLTags[i].className==theClass) {
allHTMLTags[i].style.display=’none’;
}
}
}
-----------------------------方法二.
document.getElementByClass = function (classname) {
var elements = [];
var alltags = document.all ? document.all : document.getElementsByTagName("*")
for (var i=0; i
var classNames = alltags[i].className.split(" ");
if (classNames.contain(classname))
elements[elements.length] = alltags[i];
}
return elements;
}
==================应用:
var Tags = new Array();
var j=0;
var theClass='machineheadernosort';
var allHTMLTags=document.getElementsByTagName('*');
for (var i=0; i<allHTMLTags.length; i++)
{
if (allHTMLTags[i].className==theClass) {
//allHTMLTags[i].style.display='none';
Tags[j]=allHTMLTags[i];
j++;
}
}
Tags[2].style.display='none';
/**********************/
var allHTMLTags = new Array();
function getElementByClass(theClass)
{
var allHTMLTags=document.getElementsByTagName('*');
for (i=0; i
if (allHTMLTags[i].className==theClass) {
allHTMLTags[i].style.display=’none’;
}
}
}
-----------------------------方法二.
document.getElementByClass = function (classname) {
var elements = [];
var alltags = document.all ? document.all : document.getElementsByTagName("*")
for (var i=0; i
var classNames = alltags[i].className.split(" ");
if (classNames.contain(classname))
elements[elements.length] = alltags[i];
}
return elements;
}
==================应用:
var Tags = new Array();
var j=0;
var theClass='machineheadernosort';
var allHTMLTags=document.getElementsByTagName('*');
for (var i=0; i<allHTMLTags.length; i++)
{
if (allHTMLTags[i].className==theClass) {
//allHTMLTags[i].style.display='none';
Tags[j]=allHTMLTags[i];
j++;
}
}
Tags[2].style.display='none';
本文来自博客园,作者:CarlZeng,转载请注明原文链接:https://www.cnblogs.com/backuper/archive/2008/10/07/1305949.html
需求沟通链接 扫客服加群: