用JQuery添加CSS样式

原生的JavaScript中,可以用style属性为CSS添加样式

var className=document.getElementsByClassName("box");

className.style.backgroundColor="red";

jQuery中使用JQ提供的CSS()方法添加样式

  1. $(".box").css("backgroundColor","red");                         //这个方法只能添加一个属性
  2. $(".box").css({backgroundColor:"red",fontSize:"20px:});//这个方法可以添加多个CSS样式属性

猜你喜欢

转载自blog.csdn.net/yuhui01/article/details/80806959