如何使用 js 或 jquery 删除所有属性。
(我不知道body里的属性是什么,我想把它们全部删除)
您可以使用 DOM Level 1 Coreattributes
property 以列表形式访问属性。作为普通的 JS:
function removeAllAttrs(element) {
for (var i= element.attributes.length; i-->0;)
element.removeAttributeNode(element.attributes[i]);
}
removeAllAttrs(document.body);
或者穿上 jQuery 插件的衣服:
$.fn.removeAllAttrs= function() {
return this.each(function() {
$.each(this.attributes, function() {
this.ownerElement.removeAttributeNode(this);
});
});
};
$('body').removeAllAttrs();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)