如何显示文档中所有元标记的名称属性

How to display the name attributes of all the of the meta tags in the document?

本文关键字:属性 何显示 显示 文档      更新时间:2023-09-26

我需要显示文档中所有元标记的名称属性。

我尝试使用:

var attrs = document.getElementsByTagName("meta").attributes;

但它不起作用。

你可以尝试一个简单的for循环:

var metas = document.getElementsByTagName("meta")
var names = []
for (var i = 0; i < metas.length; i ++) {
    names.push(metas[i].name)
}