1.
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title> 颜色填充div</title> <script src="jquery-1.12.3.min.js"></script> <style> div{width:100px;height: 100px; border: 1px solid black; float: left; margin: 10px} </style> </head> <body> <span>red</span> <span>yellow</span> <span>green</span> <span>black</span><br/> <div></div> <div></div> <div></div> <div></div> <script> var color = ""; $(‘span‘).click(function(){ color = $(this).html(); }); $(‘div‘).click(function(){ $(this).css(‘background‘,color); }); </script> </body> </html>
原文:http://www.cnblogs.com/bravolove/p/6063733.html