如何设置下拉列表的格式以仅使用选定的答案(取决于第一个下拉列表) [英] How to format a drop down list to use only selected answers depending on first dropdown
本文介绍了如何设置下拉列表的格式以仅使用选定的答案(取决于第一个下拉列表)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
http://whodateswhere.com/auto/
这是我正在建立的网站.
显示位置:
品牌:
型号:
我想知道,选择第一个下拉菜单后,如何让第二个下拉列表知道该菜单来自该品牌?
http://whodateswhere.com/auto/
This is my site I'm building.
Where it shows:
Make:
Model:
I'd like to know, after the first is chosen, how do I let the second drop down know it will be from that make?
这是代码:
<script type="text/javascript">
$(function(){
$.get('makes_models.php', function(data){
$('#ajax_make_select').html( data );
});
// on change of dropdown1 populate dropdown2 with the respective data
$('#ajax_make_select').change(function(){
$.get('models.php',{ make: $('ajax_make_select').val() }, function(data){
$('#ajax_model_select').html( data );
});
});
});
</script>
makes_models.php代码为:
with the makes_models.php code is:
<select>
<option value=999>Select a Make</option>
<option value=1>Acura</option>
<option value=2>Audi</option>
<option value=3>BMW</option>
</select>
如何编码第二个文件? "models.php"
如果选择了Ac歌,我希望它显示
How would I go about coding the second file? "models.php"
if Acura is chosen, I would like it to display
<option value=1>MDX</option>
<option value=2>RDX</option>
<option value=3>RL</option>
<option value=4>TL</option>
<option value=5>TSX</option>
<option value=6>ZDX</option>
推荐答案
我建议您查看 http://jsfiddle.net/tBrXt/2/
In response to how you would code the second file, use the switch/case
statement:
<?php
switch($_GET['make']) {
case "acura":
echo json_encode(array("MDX","RDX","RL","TL","TSX","ZDX"));
return;
case "ford":
echo json_encode(array('f150','mustang','etc'));
return;
}
?>
这篇关于如何设置下拉列表的格式以仅使用选定的答案(取决于第一个下拉列表)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文