Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用javascript或jquery从字符串中仅获取要列出的所有HTML标记?_Javascript_Jquery_Html - Fatal编程技术网

如何使用javascript或jquery从字符串中仅获取要列出的所有HTML标记?

如何使用javascript或jquery从字符串中仅获取要列出的所有HTML标记?,javascript,jquery,html,Javascript,Jquery,Html,如何从字符串中仅获取包含所有HTML标记的列表?我们可以使用javascript、jquery或任何C#库或api。 我们有一大串: <html> <head> </head> <body> qwe <button type="button">Click Me!</button> <a>xyz</a> <button type="button"/> </body> </h

如何从字符串中仅获取包含所有HTML标记的列表?我们可以使用javascript、jquery或任何C#库或api。 我们有一大串:

<html>
<head>
</head>
<body>
qwe
<button type="button">Click Me!</button>
<a>xyz</a>
<button type="button"/>
</body>
</html>

qwe
点击我!
xyz
我想得到list={
,,,,,,
}
我需要计算每个HTML标记在字符串中出现的次数,并显示3个最常见的标记。

这是您想要的。但是如果你搜索一下,你就能找到

$(文档).ready(函数(){
变量标记=$(“*”).map(函数(){
返回此.nodeName;
}).get()
//把重复的过滤掉
.过滤器(函数(值、索引、自){
返回self.indexOf(value)==索引;
});
控制台日志(标签);
});

qwe
点击我!
xyz
类似的内容:

var tagList = {};
var tag;
document.querySelectorAll('*').forEach(function(node) {
  tag = node.tagName.toLowerCase();
  if (!tagList[tag]) {
    tagList[tag] = 1;
  } else {
    tagList[tag]++;
  }
});
tagList; // object, where key - html tag, and value – tag count per html document

享受吧

我尝试使用HtmlAgilityPack和var bla=document.getElementsByTagName(“*”);但是我不知道下一步该做什么我正在服务器上运行这段代码,我不能使用JQuery,因为我有一个包含html的字符串,我想从中获取标记