选择2个选择标签后启用按钮


Enabling a button when 2 select tag has been selected

我正在做一个验证按钮。我有一个按钮最初处于禁用状态。我有三个元素作为按钮启用程序。1是输入标签,1是选择标签,另外1是选择标记。当填充并选择了这3个元素时,当一个或所有元素返回空白时,该按钮应启用并再次返回禁用状态。

这就是我迄今为止所做的,但没有奏效。请帮我

$(window).load(function(){
    $("#devicemask").on('keyup blur', function(){
        $('#set-sr-property').prop('enabled', this.value.trim().length);
    });
            $('#flightselect').change(function() {
                var op =$(this).val();
                if(op ! = '') {                 
                    $('#set-sr-property').prop('disabled',false);
                } else {
                      $('#set-sr-property').prop('disabled', true);
                }   
            });
            $('#crewselect').change(function() {
                var op =$(this).val();
                if(op ! = '') {                 
                    $('#set-sr-property').prop('disabled',false);
                } else {
                      $('#set-sr-property').prop('disabled', true);
                }   
            });
        });

您需要检查每个事件之间的每个值。基本上会是这样的。

var input = $('#devicemask');
var select1 = $('#flightselect');
var select2 = $('#crewselect');
var button = $('#set-sr-property');
input.on('keyup blur', function(){
    if (input.val().trim().length >= 1 &&
          select1.val() !== '' && 
          select2.val() !== '') {
          button.prop('disabled', false);
    }else{
            button.prop('disabled', true);
    }  
});
select1.change(function() {
    if (input.val().trim().length >= 1 &&
          select1.val() !== '' && 
          select2.val() !== '') {
          button.prop('disabled', false);
    }else{
            button.prop('disabled', true);
    }    
});
select2.change(function() {
    if (input.val().trim().length >= 1 &&
          select1.val() !== '' && 
          select2.val() !== '') {
          button.prop('disabled', false);
    }else{
            button.prop('disabled', true);
    }   
});

你当然可以简化它。样品小提琴https://jsfiddle.net/phv5yty8


无论如何,我试图将它封装在$.load()中,但没有成功。我不知道为什么。所以$.ready()可能适合这个。