jquery设置css样式的多种方法(总结)
设置css样式的多种方法总结,jquery
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style> </style> </head> <body> <ul> <li>兄弟多个1</li> <li>兄弟多个2</li> <li>兄弟多个3</li> <li>兄弟多个4</li> <li>兄弟多个5</li> <li>兄弟多个6</li> <li>兄弟多个7</li> <li>兄弟多个8</li> <li>兄弟多个9</li> </ul> <ul id="ul"> <li>兄弟多个1</li> <li>兄弟多个2</li> <li>兄弟多个3</li> <li>兄弟多个4</li> <li>兄弟多个5</li> <li>兄弟多个6</li> <li>兄弟多个7</li> <li>兄弟多个8</li> <li>兄弟多个9</li> </ul> <script type="text/javascript" src="jquery-1.11.1.js"></script> <script> //设置css属性 $("ul").css("backgroundColor","red"); //同时设置多值 $("ul").css({ backgroundColor: "yellow", fontSize: "16px" }); //间隔显示不一样的颜色 $("#ul li").css("color",function(index,value){ console.log(index); //当前元素的序号 console.log(value); //当前元素要设置的样式的值 if(index%2==0){ return "red"; }else{ return "blue"; } }); </script> </body> </html>
相关推荐
jiedinghui 2020-10-25
Ladyseven 2020-10-22
zuncle 2020-09-28
xiaohuli 2020-09-02
葉無聞 2020-09-01
nicepainkiller 2020-08-20
AlisaClass 2020-08-09
myloveqiqi 2020-08-09
buttonChan 2020-08-02
drdrsky 2020-07-29
Ladyseven 2020-07-25
nicepainkiller 2020-07-24
AlisaClass 2020-07-19
hellowzm 2020-07-19
background-color: blue;background-color: yellow;<input type="button" value="变蓝" @click="changeColorT
昔人已老 2020-07-19
骆驼的自白 2020-07-18
lanzhusiyu 2020-07-19
hellowzm 2020-07-19
CSSEIKOCS 2020-07-18