代码:
实例
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>彩虹球</title> <style type="text/css"> ul { padding: 0; margin: 0; width: 450px; border: 0px dashed #666; padding: 10px 5px; } ul:after { content:''; display: block; clear:both; } li { list-style: none; float: left; width: 40px; height: 40px; line-height: 40px; text-align: center; border-radius: 50%; background: skyblue; margin-right: 5px; } .bg-red {background-color: red;} .bg-orangered {background-color: orangered;} .bg-yellow {background-color: yellow;} .bg-mediumseagreen {background-color: mediumseagreen;} .bg-aqua {background-color: aqua;} .bg-mediumblue {background-color: mediumblue;} .bg-purple {background-color: purple;} } </style> </head> <body> <ul> <li id="item1">1</li> <li class="green">2</li> <li class="red">3</li> <li id="item2">4</li> <li>5<img src=""></li> <li class="black">6</li> <li class="blue">7</li> </ul> </body> </html> <script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script> <script type="text/javascript"> $('#item1').css('backgroundColor','red') $('.green').addClass('bg-orangered') $('li:nth-child(2) + li').addClass('bg-yellow') $('li:contains("4")').addClass('bg-mediumseagreen') $('li:has("img")').addClass('bg-aqua') $('li:eq(5)').addClass('bg-mediumblue') $('li:last-child').css('background-color','purple') $('li:parent').css('color','white') </script>
运行实例 »
点击 "运行实例" 按钮查看在线实例