Bootstrap Multi-Select- 无法启用 Select 当所有选项都是 Deselected/Unchecked

Bootstrap Multi-Select- Unable to Enable Select When All Options are Deselected/Unchecked

我有两个 select 允许多个 selection 使用 bootstrap select 插件服务和 payment_type。我想要的是当服务中的所有选项都已 deselected/unchecked 然后 payment_type 启用。注意:代码中的禁用工作正常,但该字段的启用没有。我是不是做错了什么?

此外,payment_type 和服务最初是禁用的,但是 select 另一个字段的离子启用。

<select id="services" class="form-control" multiple="multiple" disabled>
       <option value="tire_rotation">Tire Rotation</option>
       <option value="oil_change">Oil Change</option>
       <option value="brake_check">Brake Check</option>
 </select>


 <select id="payment_type" class="form-control" multiple="multiple" disabled>
       <option value="cash">Cash</option>
       <option value="check">Check</option>
       <option value="credit_card">Credit Card</option>
       <option value="debit_card">Debit Card</option>
 </select>
$(document).ready(function() {
       $('#services').multiselect({
           buttonWidth: '375px',
           nonSelectedText: 'Select...',
           dropLeft: true,
           includeSelectAllOption: true,
           numberDisplayed: 1,
           onChange: function() {

               var servicesSelected = $("#services :selected").length;

               if ($(servicesSelected.length != 0)) {
                  $('#payment_type').multiselect('disable');
                  $('#payment_type').multiselect("deselectAll", false).multiselect("refresh");

               } 
               else {
                    $('#payment_type').multiselect('enable');
               }
           }
       });
   });

预期结果:取消选中所有服务后,payment_type select 将启用。

这会起作用...

 $(document).ready(function() {
  $('#services').multiselect({
    buttonWidth: '375px',
    nonSelectedText: 'Select...',
    dropLeft: true,
    includeSelectAllOption: true,
    numberDisplayed: 1,
    onSelectAll: function(checked) {
      enableDisablePaymentType(checked);
    },
    onChange: function() {
      var servicesSelected = $("#services :selected").length > 0 ? true : false;
      enableDisablePaymentType(servicesSelected);
    }
  });
});

function enableDisablePaymentType(servicesSelected) {
  if (servicesSelected) {
    $('#payment_type').multiselect('disable');
    $('#payment_type').multiselect("deselectAll", false).multiselect("refresh");
  } else {
    $('#payment_type').multiselect('enable');
  }
}