2016-12-31 83 views
0

這是一個簡單的問題,但可能有人幫助我的JavaScript,它會顯示基於下拉選項是真格?僅當2個條件爲真時才顯示字段?

這是代碼我有,但我只是想知道這是否是正確的嗎?

編輯解決了以下兩個答案。非常感謝你們!

<script> 
 
function myFunction(){ 
 
$('#LoadingPlace,#DeliveryPlaces').change(function() { 
 
    if ($('#DeliveryPlaces').val() == '1' || 
 
      ["Seaport 1", "Seaport 2", "Seaport 3"].indexOf($('#LoadingPlace').val()) > -1) { 
 
     $("{#ContainerSize1").show(); 
 
     $("#ContainerFeature1").show(); 
 
\t \t $("#Genset1").show();    
 
\t \t } 
 
\t \t 
 
\t else { 
 
     $("{#ContainerSize1").hide(); 
 
     $("#ContainerFeature1").hide(); 
 
\t \t $("#Genset1").hide(); 
 
    }  
 

 
\t })}; 
 
</script>

+0

是你''&&嘗試 – prasanth

回答

0

你可以試試這個:jsfiddle.net/bharatsing/3y8n9msc/2/

另外,在你的代碼,我發現,

$("{#ContainerSize1").show(); 

這應該是

$("#ContainerSize1").show(); 

$(document).ready(function(){ 
    $('#LoadingPlace,#DeliveryPlaces').change(function() { 
     if ($('#DeliveryPlaces').val() == '1' && 
       ["Seaport 1", "Seaport 2", "Seaport 3"].indexOf($('#LoadingPlace').val()) > -1) { 
      $("#ContainerSize1").show(); 
      $("#ContainerFeature1").show(); 
     $("#Genset1").show();    
     } 

    else { 
      $("#ContainerSize1").hide(); 
      $("#ContainerFeature1").hide(); 
     $("#Genset1").hide(); 
     } 
    }); 
}); 
+1

您如何從ANS不同@prasad? –

+0

感謝的人它的工作:) – MailBlade

+0

我已經改正了錯誤代碼$(「{#ContainerSize1」)顯示()。 –

0

使用&&(其只允許無一不是如此),而不是||(它允許任何一個真)

<script> 
function myFunction(){ 
$('#LoadingPlace,#DeliveryPlaces').change(function() { 
    if (($('#DeliveryPlaces').val() == '1') && (["Seaport 1", "Seaport 2", "Seaport 3"].indexOf($('#LoadingPlace').val()) > -1)) { 
     $("{#ContainerSize1").show(); 
     $("#ContainerFeature1").show(); 
     $("#Genset1").show();    
     } 

    else { 
     $("{#ContainerSize1").hide(); 
     $("#ContainerFeature1").hide(); 
     $("#Genset1").hide(); 
    }  

    })}; 
</script> 
相關問題