<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <script src="./js/jquery.min.js"></script> <style> .geyao { width: 100px; height: 100px; background-color: pink; } </style> </head> <body> <div>1</div> <script> $(function() { $("div").click(function() { $(this).addClass("geyao"); }); //删除 /* $("div").click(function() { $(this).removeClass("geyao"); }); */ //切换 $("div").click(function() { $(this).toggleClass("geyao"); }); }) </script> </body> </html>