在原生的JavaScript中,可以用style属性为CSS添加样式
var className=document.getElementsByClassName("box");
className.style.backgroundColor="red";
在jQuery中使用JQ提供的CSS()方法添加样式
- $(".box").css("backgroundColor","red"); //这个方法只能添加一个属性
- $(".box").css({backgroundColor:"red",fontSize:"20px:});//这个方法可以添加多个CSS样式属性