如何在 2 个下拉列表中显示 Switch/Case

发布于 2024-12-10 14:27:07 字数 701 浏览 2 评论 0原文

我有一个包含 switch/case 的 php 文件,我相信它是 JSON 格式的。 请原谅我对 php/ajax/json 的了解,我真的很想学习这个。

<?php
    switch($_GET['make']) {
        case "Acura":
            echo json_encode(array("MDX","RDX","RL","TL","TSX","ZDX")); 
            return;

        case "Audi":
            echo json_encode(array("A3","A4","A5","A6","A8","Q5","Q7","R8","S4","S5","S6","TT","TTS")); 
            return;
    } 
?>

这是我拥有的文件,它包含所有品牌/型号。我将如何创建一个显示所有品牌“Acura”、“Audi”的下拉列表,然后有第二个下拉列表来填充模型。如果我选​​择 Acura,第二个下拉列表将显示 MDX、RDX、RL、TL、多伦多证券交易所、ZDX
http://whodateswhere.com/auto/ 我在这里设置了开发站点,但它不起作用。我怎样才能让它在我的网站上运行?

感谢您的帮助!

I have a php file that contains switch/case which is in JSON I believe.
Please excuse me on my knowledge of php/ajax/json, really trying to learn this.

<?php
    switch($_GET['make']) {
        case "Acura":
            echo json_encode(array("MDX","RDX","RL","TL","TSX","ZDX")); 
            return;

        case "Audi":
            echo json_encode(array("A3","A4","A5","A6","A8","Q5","Q7","R8","S4","S5","S6","TT","TTS")); 
            return;
    } 
?>

This is the file I have, it has all makes/models. How would I go about creating a drop downlist that shows all makes,"Acura,"Audi", then have a second dropdown that would populate with models. If I selected Acura, the second dropbox would show MDX, RDX, RL, TL, TSX, ZDX

http://whodateswhere.com/auto/
I have the dev site set-up here but it's not functional. How would I be able to make it work on my site?

Thanks for your help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

零度℉ 2024-12-17 14:27:08
$('#ajax_make_id').change(function(){
    $.get('model.php',{ make: $(this).html() }, function(data){
        $drop_down_data = get_options( $.parseJSON(data) ); 
        $('#ajax_model_id').html( options ); 
    }); 
}); 

function get_options( options_array )
{
    var options = ''; 
    for( var i in options_array )
         options += '<option value="'+ options_array[i] +'">' 
                    + options_array[i] +'</option>'; 
    return options; 
}
$('#ajax_make_id').change(function(){
    $.get('model.php',{ make: $(this).html() }, function(data){
        $drop_down_data = get_options( $.parseJSON(data) ); 
        $('#ajax_model_id').html( options ); 
    }); 
}); 

function get_options( options_array )
{
    var options = ''; 
    for( var i in options_array )
         options += '<option value="'+ options_array[i] +'">' 
                    + options_array[i] +'</option>'; 
    return options; 
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文