<div class="htmlarea"> <textarea id="runcode91065"> <script language="javascript" type="text/javascript"> function GetClass(className){return getElementsByClassName(className)} var $c=function(array){var nArray = [];for (var i=0;i<array.length;i++) nArray.push(array[i]);return nArray;}; Array.prototype.each=function(func){for(var i=0,l=this.length;i<l;i++) {func(this[i],i);};}; var getElementsByClassName=function(cn){ var hasClass=function(w,Name){ var hasClass = false; w.className.split(' ').each(function(s){ if (s == Name) hasClass = true; }); return hasClass; }; var elems =document.getElementsByTagName("*")||document.all; var elemList = []; $c(elems).each(function(e){ if(hasClass(e,cn)){elemList.push(e);} }) return $c(elemList); }; window.onload=function(){alert("共找到"+GetClass("test").length+"个带有test标记的对象")} </script> <input type="button" id="ceshi" value="显示这条记录"> <div id="box" class="test"> <input type="button" value="显示这条记录1"> <input type="button" class="test" value="显示这条记录2"> <input type="button" class="test" value="显示这条记录3"> </div> <input type="button" class="test" value="显示这条记录4"> <div class="test"></div> <div class="test"></div> <dl class="test"></dl> </textarea><br><input onclick="runEx('runcode91065')" type="button" value="运行代码"> <input onclick="doCopy('runcode91065')" type="button" value="复制代码"> <input onclick="doSave(runcode91065)" type="button" value="保存代码">[Ctrl+A 全选 注:<a href="http://www.jb51.net/article/23421.htm" title="查看具体详情" target="_blank">如需引入外部Js需刷新才能执行</a>]</div>