far*_*oft 10 javascript jquery attributes
如何从js或jquery中删除所有属性.(我不知道身体里的属性是什么,我想要删除它们)
bob*_*nce 19
您可以使用DOM Level 1 Core attributes属性作为列表访问属性.作为普通的JS:
function removeAllAttrs(element) {
for (var i= element.attributes.length; i-->0;)
element.removeAttributeNode(element.attributes[i]);
}
removeAllAttrs(document.body);
Run Code Online (Sandbox Code Playgroud)
或者穿着jQuery插件衣服:
$.fn.removeAllAttrs= function() {
return this.each(function() {
$.each(this.attributes, function() {
this.ownerElement.removeAttributeNode(this);
});
});
};
$('body').removeAllAttrs();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8456 次 |
| 最近记录: |