function getByClass(cName)  {
	if (document.getElementsByClassName)
		return document.getElementsByClassName(cName); 
	else {
        var arr = [];
        var allElements = document.getElementsByTagName('*');
        for (var i = 0; i < allElements.length; i++) {
            var allCNames = allElements[i].className.split(' '); 
            for (var j = 0; j < allCNames.length; j++) {
				if (allCNames[j] == cName) {
					arr.push(allElements[i]);
					break;
				}
			}                                                       
		}
		return arr;
	}  
}

本文转载:CSDN博客