原生 js 修改属性
1.setAttribute
描述:设置元素的【属性】
语法:元素名.setAttribute('属性','属性值');
例子:
box.setAttribute('style','background-color:red;height:400px');
注意:设置的是行内样式
2.getAttribute
描述:获取属性值
语法:元素名.getAttribute('属性名');
例子:
console.log(box.getAttribute('style'));//background-color:red;height:300px
注意:
只能获取行内样式
3.removeAttribute()
描述:删除一个属性
语法:元素名.removeAttribute('属性名');
例子:
box.removeAttribute('style');
4. 最古老的方式
描述 : element.属性
btn.id = 'qwe'