1<! DOCTYPE html>234<meta charset= "UTF-8" >5<title> Package Getelementsbyclassname</title>67<body>8<div class= "TRSD Demo" >1111111111</div>9<div>2222222222</div>Ten<div class= "Demo" >3333333333333</div> One<div>44444444</div> A<div>55555555555</div> -<div>6666666666666</div> -<div class= "Demo2 TSSR Demo" >777777777777777</div> the<div>88888888888</div> -<div class= "Demo" >999999999999999</div> -<div>0000000000000000</div> -<script> + functiongetclass (classname) { - if(document.getelementsbyclassname) { + returndocument.getelementsbyclassname (classname); A } at - var$elements = document.getElementsByTagName (' * '); - vararr = []; - for(vari = 0, j = $elements. Length; I < J; i++) { - //If there are multiple classes that need to be separated by spaces - varDom = $elements [I].classname.split (""); in for(vark = 0, L = dom.length; K < L; k++) { - if(Dom[k] = =classname) { to Arr.push ($elements [i]); + } - } the } * $ returnarr;Panax Notoginseng } - the varTest = GetClass ("Demo"); + console.log (test); A for(vari=0;i<test.length;i++){ theTest[i].style.background= "#666"; + } - $</script> $</body> -JS Get class Compatible