<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> <script src="jquery-1.11.2.min.js"></script> <style type="text/css"> .aa{ width:200px; height:200px; float:left; margin:5px; background-color:#3F6} </style> </head> <body> <div class="aa"> </div> <div class="aa"> </div> <div class="aa"> </div> <div class="aa"> </div> <div class="aa"> </div> <div class="aa"> </div> <div class="aa"> </div> <div class="aa"> </div> <div class="aa"> </div> <div class="aa"> </div> <div class="aa"> </div> <div class="aa"> </div> <div class="aa"> </div> <div class="aa"> </div> <div class="aa"> </div> </body> <script type="text/javascript"> $(".aa").click(function(){ //所有元素背景色变成原来的 $(".aa").removeAttr("xz"); $(".aa").css("background-color","#3F6"); //找到点击了谁 $(this).attr("xz","1"); $(this).css("background-color","red"); }) $(".aa").mousemove(function(){ //所有元素背景色变成原来的 $(".aa").css("background-color","#3F6"); //找到点击了谁 $(this).css("background-color","yellow"); $("[xz='1']").css("background-color","red"); }) </script> </html>