属性模块

setAttribute
getAttribute
removeAttribute
var el = document.createElement("div")
el.setAttribute("xxx", "1")
el.setAttribute("XxX", "2")
el.setAttribute("XXx", "3")
console.log(el.getAttribute("xxx"))
console.log(el.getAttribute("XxX"))

如何区分固有属性与自定义属性

// 是否是自定义属性
function isAttribute(attr, host){
    //有些属性是特殊元素才有的,需要用到第二个参数
    host = host || document.createElement("div");
    return host.getAttribute(attr) === null && host[attr] === void 0
}
原文地址:https://www.cnblogs.com/jzm17173/p/5891358.html