JS案例:显示当前HTML文档中所有的标签名
来自CloudWiki
<!doctype html> <html> <head> <meta charset="utf-8"> <title>使用集合对象显示所有标签</title> </head> <body> <p><a href="http://www.ryjiaoyu.com">人邮教育</a> <a href="http://www.ptpress.com.cn">人民邮电出版社</a> <div align="center">这一段代码是为测试DOM集合对象的用法而设置的</div> </p> <hr /> <h3>本文档使用了以下 HTML 标签:</h3> <pre> <script type="text/javascript"> var i,cell; for(i=0;i<document.all.length;i++){//遍历文档中的所有标签 cell=document.all[i]; if(i>0) document.write(", "); document.write(cell.tagName);//输出页面元素标签名 } </script> </pre></body></html>