1.修改样式
document.getElementById("container").style.color = "red";
document.getElementById("container").style.backgroundColor = "000"; //样式为连字符的改为驼峰式
2.修改替换类名
document.getElementById('container').className='newContainer';
本文介绍如何使用JavaScript来修改HTML页面中指定元素的颜色、背景颜色及类名。通过getElementById方法获取元素,之后利用style属性修改颜色和背景颜色,并通过className属性更新元素的类名。
1.修改样式
document.getElementById("container").style.color = "red";
document.getElementById("container").style.backgroundColor = "000"; //样式为连字符的改为驼峰式
2.修改替换类名
document.getElementById('container').className='newContainer';
713
1443
2620

被折叠的 条评论
为什么被折叠?