我正在尝试查找页面内的任何标签是否包含 js 事件属性,例如 onload、onunload、onfocus 等……为此,我有一系列事件要检查(我想我有它们全部):
var attr = [
"onLoad",
"onunload",
"onclick",
"ondblclick",
"onmousedown",
"onmouseup",
"onmouseover",
"onmousemove",
"onmouseout",
"onfocus",
"onblur",
"onkeypress",
"onkeydown",
"onkeyup",
"onsubmit",
"onreset",
"onselect",
"onchange"];
然后我得到所有 elementsByTagName 并想检查它们的属性:
var getAttrs = function() {
var i = 0,
j,
all = document.getElementsByTagName('*'),
max = all.length,
eventsLen = attr.length;
for (; i < max; i++) {
console.log('iterating through objects');
for (j = 0; j < eventsLen; j++) {
if (all[i].hasAttribute(attr[j])) {
console.log('found an instance of an intrinsec event', attr[j]);
}
}
}
};
这不起作用,我没有得到任何我想找到的属性。
此外,我想在所有使用 javascript 的标签中查找所有属性:(例如在 <a href="javascript:void(0)"> 中)知道如何将其添加到函数的逻辑中吗?
谢谢!