'if' 语句不起作用。我正在尝试使用类按钮来“清除所有”或“选择所有”单选按钮。为什么?

问题描述 投票:0回答:0

我无法解决的问题是“if”语句似乎没有以正确的方式工作,它向后工作?

$(document).ready(function() {
  $(".clearAllBtn").click(function() {
    var txt = $(this).html();
    if ($(this).html() === 'Clear all') {
      $(".radioFit").each(function() {
        $(this).prop('checked', false);
      });
      $(this).html("Select all")
    } else {
      $(".radioFit").each(function() {
        $(this).prop('checked', true);
      });
      $(this).html("Clear all")
    }
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

jquery radio-button
© www.soinside.com 2019 - 2024. All rights reserved.