2016-12-31 77 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> 
相关问题