How do i disable a submit button when checkbox is uncheck?

后端 未结 7 1533
再見小時候
再見小時候 2020-11-27 21:06

I have something here that cannot seem to help me disable the submit button. any ideas?

<         


        
相关标签:
7条回答
  • 2020-11-27 21:40

    Before jQuery 1.6 attr was OK, after 1.6 you must use prop.

    $('#checky').click(function(){
      $('#postme').prop('checked', !$(this).checked);
    })
    

    Attributes and properties are different things, but unfortunately jQuery took a long time to differentiate between them.

    See also: .prop() vs .attr()

    0 讨论(0)
  • 2020-11-27 21:42

    change $(this).checked to if($(this).attr('checked') == false){

    Here you go.

    0 讨论(0)
  • 2020-11-27 21:42

    Add to the button #postme a click event that checks if the check box is checked. If it is checked, return false, otherwise return true.

    $('#postme').click( function () {
        if ( !$('#checky').attr('checked') ) {
            return false;
        }
    });
    
    0 讨论(0)
  • 2020-11-27 21:54

    Try this

    $(document).ready(function(){
                    $("#postme").attr("disabled","disabled");
                        $("#checky").click(function(){
                            if($("#checky").is(":checked")){
                             $("#postme").removeAttr("disabled");   
                             }
                            else{
                                $("#postme").attr("disabled","disabled");
                                }
                        });
                    })
    
    0 讨论(0)
  • 2020-11-27 21:55

    Try this way

    $('#checky').click(function(){
    
        if(this.checked == false){
             $('#postme').attr("disabled","disabled");   
        }
        else {
            $('#postme').removeAttr('disabled');
        }
    });
    
    0 讨论(0)
  • 2020-11-27 22:02
    if(!$(this).is(':checked') ...
    
    0 讨论(0)
提交回复
热议问题