jquery toggleClass() 切换类样式

例子

类似下面按钮,点以下变成 蓝色,在点一下又切换成默认样式

html:

<input value="切换样式" type="button" id="btn">

css:

<style>
    #btn{
        width: 80px;
        height: 50px;
    }
    .press{
        background-color: #5bc0de;
    }
</style>

js:

<script src="scripts/jquery.min.js"></script>
<script>
  $("#btn").click(function () {
      //切换样式
      $(this).toggleClass("press")
  })
</script>

原文出处:https://malaoshi.top/show_1IX5pvqnLJ61.html