【问题标题】:input that is a select/pulldown/autocomplete but also allows user to enter value laravel输入是选择/下拉/自动完成,但也允许用户输入值 laravel
【发布时间】:2016-06-19 16:32:00
【问题描述】:

我正在使用 Laravel 制作一个 Web 应用程序,其中一部分是用户指定他们的居住地。当他们在国家/地区选择中选择一个国家时,使用 AJAX 使用该国家/地区的州填充州输入(“下拉菜单”)。当他们选择一个州时,它使用 AJAX 用该州的城市填充城市输入(“下拉菜单”)。世界上有如此多的州和城市,州和城市的 mySQL 表将根据用户的输入来填充。

如何使用 Laravel 和 jQuery 进行选择/下拉/自动完成输入,以允许 1)用户根据先前选择的值从存储在数据库中的值列表中选择一个选项,以及 2)添加一个新值如果没有呢?

下面是我尝试将国家和州的输入链接在一起:

//get id of country selected, AJAX to database and return an array of it's states
$("#country_id").change(function(){
    var country_id = $(this).val();
    $.ajax({
        url:base_url + "/locations/stateJSON",
        data:{country_id:country_id},
        success: function(states) {
            //console.log(states);
        }
    });
});

//state's input is text input jQuery autocomplete populated with selected country's states
$("#state_id").autocomplete({
    source: states,
    minLength: 1
});

【问题讨论】:

    标签: javascript jquery jquery-ui laravel laravel-4


    【解决方案1】:

    您不能使用带有基于 ajax 响应的选项的数据列表,接受新值,以便下次使用这些新值填充数组吗?

    Datalist from html-5.com

    【讨论】:

    • 正在研究数据列表。
    猜你喜欢
    • 2011-03-13
    • 2013-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-31
    相关资源
    最近更新 更多