1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title></title> 5 <style> 6 .box { 7 400px; 8 height: 100px; 9 background: cyan !important; 10 cursor: pointer; 11 } 12 </style> 13 </head> 14 <body> 15 <div class="box"> 16 <p>hello world</p> 17 </div> 18 <script type="text/javascript" src="jquery-1.11.3.js"></script> 19 <script> 20 $('.box').click(function () { 21 $(this).css('cssText', 'background: yellowgreen!important') 22 }) 23 </script> 24 </body> 25 </html>
这样就可以在点击后更改div的background