1、新建HTML文件
2、引入jquery.min.js文件
3、创建css样式
4、创建div和按钮并添加class样式
5、预览效果图
6、创建js点击事件
7、当点击按钮样式切换
8、点击按钮效果如图
9、再点击按钮,效果变回之前的效果,附上源码<script>$(function()辘腋粪梯{ $("button").click(熠硒勘唏function(){ $("div").toggleClass("blue"); });});</script></head><style>.red{ width:400px; height:200px; line-height:200px; color:#0F0; background:#F33;}.blue{background:#0F0; color:#FFF;}</style>