Labels and hidden fields in Internet Explorer (and jquery)

前端 未结 5 1780
日久生厌
日久生厌 2021-02-05 12:36

I\'m having trouble checking hidden checkboxes in IE. This is the base html:



        
5条回答
  •  借酒劲吻你
    2021-02-05 13:15

    You could try added an onclick to the label to get around the IE issues.

    $('label').click(function() {
      $('#' + $(this).attr('for')).click();
    });
    

    If that does not work, try setting the attribute manually.

    $('label').click(function() {
      var checkbox = $('#' + $(this).attr('for'));
      if (checkbox.is(':checked')) {
        checkbox.removeAttr('checked');
      } else {
        checkbox.attr('checked', 'checked');
      }
    });
    

提交回复
热议问题