在原生的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样式属性
如果觉得《JQuery——添加CSS样式》对你有帮助,请点赞、收藏,并留下你的观点哦!