检查复选框是选中还是取消选中

我想知道用户是否选中了复选框,如果是,则应该禁用日期;如果未选中,则启用日期。复选框上有更改事件


$('input[type=checkbox]:checked').click(function () {

        if ($('#chkShowAll').prop('checked')) {

            $("#MainContent_txtSrchFromDate").attr('readonly', 'readonly');

            $("#MainContent_txtSrchToDate").attr('readonly', 'readonly');

        }


        else {

            $("#MainContent_txtSrchFromDate").removeAttr('readonly', 'readonly');

            $("#MainContent_txtSrchToDate").removeAttr('readonly', 'readonly');

         }

    });


冉冉说
浏览 187回答 4
4回答

开满天机

这是简短而简单的。 $('input[type=checkbox]').on('click', function() {         $('#MainContent_txtSrchToDate').prop('disabled', $(this).is(":checked"));  });

莫回无

试试这个:$('input[type=checkbox]').click(function() {  let dateElements = $("#MainContent_txtSrchFromDate, #MainContent_txtSrchToDate");  if ($(this).is(":checked")) {    dateElements.prop("readonly", true);  } else {    dateElements.prop("readonly", false);  }});

米脂

要检查一个复选框是否被选中,你可以简单地这样做:$('#chkShowAll').checked如果选中则返回 true 否则返回 false

UYOU

if($("#checkbox_id").is(':checked')){ console.log("checked");}else{  console.log("not checked");}此显示复选框是否选中
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript