使用JavaScript增加元素属性
找到元素
//通过 id 查找 HTML 元素
document.getElementById("intro");
//通过标签名查找 HTML 元素
getElementsByTagName("p")
//通过类名找到 HTML 元素
document.getElementsByClassName("intro");
修改
//添加属性:
obj.setAttribute('attr_name','attr_value');
//获取属性值:
obj.getAttribute('attr_name');
//删除属性:
obj.removeAttribute('attr_name');