jQuery操作类的相关方法
<!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=\"jquery-3.3.1.min.js\"></script><style>div{height: 200px;width: 200px;}.class1{background: red;}.class2{border: 1px solid black;}</style><script>$(function(){var btu = document.getElementsByTagName(\"button\");btu[0].onclick= function(){$(\'div\').addClass(\"class1 class2\")//添加类};btu[1].onclick = function(){$(\'div\').removeClass(\"class1\")//删除类}btu[2].onclick = function(){$(\'div\').toggleClass(\"class1\")//有类class就删除,没有就增加}})</script></head><body><button>增加</button><button>删除</button><button>替换</button><div></div></body></html>