<!doctype html> <html> <head> <meta charset="UTF-8"> <title>Document</title> <style type="text/css"> *{ padding: 0; margin: 0; } .news li{ list-style-type: none; display: inline-block; background-color: #666; padding: 10px; } #box{ width: 200px; margin: 0 auto; } #box .color li{ display: inline-block; margin: 10px; width: 20px; height: 20px; } #box .color li:nth-child(1){ background-color: red; } #box .color li:nth-child(2){ background-color: yellow; } #box .color li:nth-child(3){ background-color: blue; } #box .color li:nth-child(4){ background-color: pink; } .it:before{ content: "√"; } </style> <script type="text/javascript" src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script> </head> <body> <div id="box"> <div id="box1"> <ul class="color"> <li></li> <li></li> <li></li> <li></li> </ul> </div> <ul class="news"> <li>时事新闻</li> <li>娱乐新闻</li> </ul> </div> </body> <script> $().ready(function () { $(".color>li").click(function () { $(this).addClass("it").siblings().removeClass("it"); console.log($(this).css("backgroundColor")); var bgc = $(this).css("backgroundColor"); $(".news>li").css("backgroundColor", bgc) }) }) </script> </html>
IT自学