清理 Excel 导出的 HTML 的多余属性

var whiteList = ["rowspan", "colspan"];

[...document.querySelectorAll("table")].forEach(table => {
  rmAttr(table);
  [...table.querySelectorAll("tr")].forEach(tr => {
    rmAttr(tr);
    [...tr.querySelectorAll("td")].forEach(td => {
      rmAttr(td);
    });
  });
  console.log(table.outerHTML);
});

function rmAttr(dom) {
  [...dom.attributes].forEach(attr => {
    if (!~whiteList.indexOf(attr.name)) {
      dom.removeAttribute(attr.name);
    }
  });
}
原文地址:https://www.cnblogs.com/jffun-blog/p/11042960.html