Disable or enable Submit button on Checkbox checked event

前端 未结 4 2154
陌清茗
陌清茗 2020-12-30 13:57

I want something like this but with a slight change. I want a Button to be enabled or disabled on Checkbox checked event, i.e. when checkbox is checked then and then only b

相关标签:
4条回答
  • 2020-12-30 14:24

    Seriously? Why not just:

    onclick="$('#submitButton').attr('disabled',$('#checkbox').is(':checked'));"
    
    0 讨论(0)
  • 2020-12-30 14:26
    $(function() {
        $('#id_of_your_checkbox').click(function() {
            if ($(this).is(':checked')) {
                $('#id_of_your_button').attr('disabled', 'disabled');
            } else {
                $('#id_of_your_button').removeAttr('disabled');
            }
        });
    });
    

    And here's a live demo.

    0 讨论(0)
  • 2020-12-30 14:26
    $('#checkbox').click(function(){
        if($(this).is(':checked')){
            $('#submitButton').attr("disabled", "true");
        }else {
            $('#submitButton').removeAttr("disabled");
        }
    
    });
    

    ... it works for me ...

    0 讨论(0)
  • 2020-12-30 14:31

    This is old but worked for me with jquery 1.11

    <script>
    $(function() {
        $('#checkbox-id').click(function() {
            if ($(this).is(':checked')) {
                $('#button-id').removeAttr('disabled');
            } else {
                $('#button-id').attr('disabled', 'disabled');
            }
        });
    });
    </script>
    

    the if instruction swapped with the else instruction and in the button html markup add disabled="disabled"

    may help someone

    Jquery:

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    
    0 讨论(0)
提交回复
热议问题