给一组标签设置状态

Table of Contents

    如下一组标签,当鼠标点击后设置active状态,再次点击取消active状态

          <div class="field required">
            <label class="required">标签</label>
            <a class="ui teal tag label">Windows</a>
            <a class="ui red tag label">Linux</a>
            <a class="ui blue tag label">Mobile</a>
            <a class="ui yellow tag label">C/C++</a>
            <a class="ui green tag label">Qt</a>
            <a class="ui purple tag label">Node.js</a>
            <a class="ui black tag label">Web</a>
          </div>
    
      $(".tag.label").on("click", function() {
        if ($(this).hasClass('active')) {
          $(this).removeClass('active');
        } else {
          $(this).addClass('active');
        }
      });