如何使用JavaScript生成页面中不同HTML标签的列表(必须在IE6中使用) [英] How would I generate a list of distinct HTML tags in a page using JavaScript (must work in IE6)

查看:94
本文介绍了如何使用JavaScript生成页面中不同HTML标签的列表(必须在IE6中使用)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最后的结果是一个包含HTML文档中使用的标签名称列表的JavaScript数组,例如:

The end result I'm after is a JavaScript array containing a list of tag names that are used in the HTML document eg:

div,span,section, h1,h2,p,etc ...

div, span, section, h1, h2, p, etc...

我希望列表不同,我对 (但是如果它是排除他们的性能,他们可以在那里)。

I want the list to be distinct and I'm not interested in tags within the <head> of the document (but they can be there if it's a performance hog to exclude them).

这必须在IE 6中工作,7,& 8,我不想使用jquery。

This has to work in IE 6, 7, & 8 and I don't want to use jquery.

这样做最有效的方法是什么?

What would be the most efficient way of doing this?

推荐答案

您正在寻找的是 document.all.tagName
在我的头顶,这样做的循环应该这样做(假设你要过滤你不想要的标签)

What you're looking for is document.all.tagName At the top of my head, a for loop like this should do it (providing that you're gonna filter the tags you don't want on that list)

for(i = 0; i < document.all.length; i++)
{
  console.log(document.all[i].tagName);
}

这篇关于如何使用JavaScript生成页面中不同HTML标签的列表(必须在IE6中使用)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆