2017-03-15 101 views
0

我有一個文本框#Email,我有兩個下拉列表菜單是#Carriers和#Phones。當輸入電子郵件時,我想只啓用運營商下拉框,但不是電話。當選擇運營商時,必須啓用電話下拉列表。電話下拉列表只能在選擇電子郵件和運營商時啓用。如果用戶輸入電子郵件並從#carriers和#phones中選擇一個項目,然後刪除電子郵件,則必須禁用兩個下拉菜單。有沒有辦法可以做一個複合句子?以下是輸入電子郵件時的工作承運人。如何在文本框中包含數據和下拉列表時選擇啓用第二個下拉列表?

  $(document).ready(function() { //Will check for e-mail and enable #Phones dropdownlist, otherwise, it will disable dropdownlist of #Phones 
      $('#Email').on('input change', function() { //check to see if email textbox is empty 
     if ($(this).val() == '') { 
      $('#Phones').prop('disabled', true); 
     } 
     else { 
      $('#Phones').prop('disabled', false); 
     } 
    }); 
}); 

需要這包括#Phones & &載波數目

<script> 
$(document).ready(function() {//need this to enable when email and carriers is selected. 
    $('#Email').on('input change', function() { //check to see if email is empty 
      if ($(this).val() == '') { 
      $('#Phones').prop('disabled', true); 
      } 
     else { 
      $('#Phones').prop('disabled', false); 
     } 
    }); 
}); 

回答

1
$('#Email').on('input change', function() { //check to see if email is empty 
     if ($(this).val() == '') { 
     $('#Carriers').prop('disabled', true); 
     $('#Phones').prop('disabled', true); 
     } 
    else { 
     $('#Carriers').prop('disabled', false); 
    } 
}); 

這將使運營商在更改電子郵件,但會禁止運營商和手機如果你刪除它。

$('#Carriers').change(function() { 
     if ($('#Carriers').val() == '') { 
     $('#Phones').prop('disabled', true); 
     } 
    else { 
     $('#Phones').prop('disabled', false); 
    } 
}); 

並且當您更改運營商時,這將啓用電話。您已經在第一時間查看電子郵件並在沒有任何價值的情況下停用運營商,因此您不需要在此再次執行此操作。

+0

嗯..我使用了底部聲明,但是當我刪除電子郵件地址時,#Carries禁用而不是#Phones。它現在的工作方式是,用戶輸入電子郵件和#carriers啓用,用戶選擇#carriers和#phones啓用項目。當我擦除#電子郵件時,禁止#載體但#電話仍處於啓用狀態。 – Sandy2016

+0

編輯我的答案。第二個功能添加了「#電子郵件」。你現在可以檢查一下嗎? – ReadyFreddy

+0

我希望它工作的方式是,當用戶從#carriers和#phones中選擇項目,然後刪除電子郵件時,必須禁用下拉菜單。目前,#運營商只會禁用而不是#電話。 – Sandy2016

相關問題