【问题标题】:dynamically show selected value in select list dropdown in codeigniter在 codeigniter 的选择列表下拉列表中动态显示所选值
【发布时间】:2015-06-16 11:08:30
【问题描述】:

我使用 Ajax 请求和选择框在我的应用程序中为国家/地区城市创建了级联下拉列表。我的应用程序收集有关用户的信息,即个人信息等。在我的应用程序中,有一个编辑输入字段的选项。单击编辑按钮后,个人信息页面将填充以前输入的数据。现在我需要帮助来显示选定的值,即用户在我的选择框下拉列表中选择了哪个国家、州和城市。请帮忙!!

【问题讨论】:

    标签: ajax codeigniter


    【解决方案1】:

    在您看来,将先前选择的值分配给 javascript var。然后当ajax请求成功时,从var中设置下拉值。

    这是一个使用 jQuery 的示例。

    // set a js var from a php var passed to the view from CI
    var previous_country = <?=$previous_country?>;
    
    $.ajax({
        // your ajax options here (url, datatype, etc)
        success: function(response){
            // code to populate dropdown here
            // then set the dropdown value to change the selected item:
            $('select#country').val(previous_country);
        }
    });
    

    【讨论】:

      猜你喜欢
      • 2012-08-12
      • 2017-05-11
      • 1970-01-01
      • 2021-10-26
      • 1970-01-01
      • 1970-01-01
      • 2020-03-11
      • 1970-01-01
      • 2020-01-24
      相关资源
      最近更新 更多