Fill dropdown list with json

前端 未结 3 1966
眼角桃花
眼角桃花 2021-01-03 05:47

I have SQLite table with columns id and name. I return array of those rows like json from autocomplete.php page. How to fill select with options ( drop down list ) with this

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-03 06:40

    HTML:

    
    

    JavaScript:

    $(function() {
        var data = [
            {
            "id": "1",
            "name": "test1"},
        {
            "id": "2",
            "name": "test2"}
        ];
        $.each(data, function(i, option) {
            $('#sel').append($('

    Here's a working example. http://jsfiddle.net/ms2Ma/

提交回复
热议问题