jQuery detect click on disabled submit button

后端 未结 10 950
日久生厌
日久生厌 2020-12-03 06:20

Fiddle: http://jsfiddle.net/ugzux/

As you can see, I have a form with a disabled (via javascript) submit button.

I want to be able to bind a click event to

10条回答
  •  爱一瞬间的悲伤
    2020-12-03 06:57

    An other workaround with combination of a required checkbox could be:

    
    
    U need to check this box

    CSS-Magic

    #submitButton{
    display:inline-block;
    color:#D00019;
    width:160px;
    z-index:30;
    position:absolute;
    display:block;
    top:0;
    left:0;
    height:30px;
    outline:none;
    }
    
    #submitButton.nope{
    z-index:10;
    color:#333;
    }
    
    .button_outer {
    width:162px;
    height:32px;
    z-index:50;
    position:relative;
    }
    
    span.button_overlay{
    display:block;
    height:30px;
    width:162px;
    position:absolute;
    top:0;
    left:0;
    background:#fff;
    opacity:0.3;
    filter: alpha(opacity=30);
    z-index:20;
    }
    
    .einweilligung_hinweis_error{
    color:red;
    }
    

    JQuery-Stuff

    (document).ready(function() {
    
      $('.einwilligung').click(function() {
        var buttonsChecked = $('.einwilligung:checked');
        if (buttonsChecked.length) {
          $('#submitButton').removeAttr('disabled');
          $('#submitButton').removeClass('nope');
          $('.einwilligung_hinweis').removeClass('einweilligung_hinweis_error');
        }
        else {
          $('#submitButton').attr('disabled', 'disabled');
          $('#submitButton').addClass('nope');
        }
      });
    
      $('.button_outer').click(function(){
         if($('#submitButton').hasClass('nope')){
              $('.einwilligung_hinweis').addClass('einweilligung_hinweis_error');
          }else{
              $('.einwilligung_hinweis').removeClass('einweilligung_hinweis_error');
          }
      });
    
    });
    

    Maybe not state of the art, but it works pretty well!

    • the checkbox needs to be checked for giving the submit button a higher z-index
    • if not, there is the button_overlay above, with a click event on it, for highlighting the message

提交回复
热议问题