<form method="get" action="processform.php">
<b>SELECT SERVICE</b><select name="Service">
<option value="">Select a Service</option>
<option value="toairport">To Airport</option>
<option value="fromairport">From Airport</option>
<option value="DriveAround">Drive Around</option>
<option value="PointToPoint">Point TO Point</option>
<option value="Wedding">Wedding</option>
<option value="Prom">Prom</option>
<option value="Graduation">Graduation</option>
<option value="Birthday">Birthday</option>
<option value="Concert">Concert</option>
<option value="SportingEvents">Sporting Events</option>
<option value="Anniversary">Anniversary</option>
</select>
Airports<select name="airports">
<option value="">Select an Airport</option>
<option value="LGA">LaGuardia</option>
<option value="JFK">Jonh F. Kennedy</option>
<option value="Westchester">Westchester</option>
<option value="Terteboro">Terteboro</option>
<option value="Islip">Islip</option>
</select>
我有上面的代码,在服务部分,当我点击“从机场或机场我想要机场选项显示。 提前谢谢
答案 0 :(得分:1)
我建议:
$('select[name="Service"]').change(function(){
var v = $(this).val().toLowerCase();
$('select[name="airports"]').toggle((v == 'toairport' || v == 'fromairport'));
}).change();
您还可以使用简单的正则表达式来测试value
以单词airport
结尾(符合发布的要求,因为您测试的两个选项都以字符串'airport'):
$('select[name="Service"]').change(function(){
var v = $(this).val().toLowerCase();
$('select[name="airports"]').toggle(v.match(/airport$/));
}).change();
参考文献:
答案 1 :(得分:0)
试试这个
$("select[name=Service]").change(function(e){
if(e.target.value == "toairport" || e.target.value == "fromairport"){
$("select[name=airports]").show();
}else{
$("select[name=airports]").hide();
}
})
答案 2 :(得分:0)
您可能正在寻找:
$("#airports").hide()
$("#service").change(function(){
if(this.value == 'toairport' || this.value == 'fromairport')
$("#airports").show();
else
$("#airports").hide();
});
<强>标记:强>
<select name="Service" id="service">
<select name="airports" id="airports">
DEMO - &gt; http://jsfiddle.net/jA56n/