// 获取所有的标签,拿到所有的属性(class同理)
function getAllElementsWithAttribute(attribute)
{
var matchingElements = [];
var allElements = document.getElementsByTagName('*');
for (var i = 0, n = allElements.length; i < n; i++)
{
if (allElements[i].getAttribute(attribute) !== null)
{
// Element exists with attribute. Add to array.
matchingElements.push(allElements[i]);
}
}
return matchingElements;
}
// 用法 匹配<div show-controller="xxx"></div>
if(document.querySelectorAll) {
var __node = document.querySelectorAll("[show-controller]");
} else {
var __node = getAllElementsWithAttribute("show-controller")
}
整理归纳了stackOverFlow的一篇问答