Use JQUERY/JSON to auto fill select dropdown boxes

前端 未结 2 937
南笙
南笙 2021-01-16 20:20

OK I spent spent a lot of time looking over examples but can\'t find one which helps me enough for my situation. I have a JSON file, simplified for this example:

<         


        
2条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-16 21:10

    Try something like this. You should really have a value property for your options. I added a data-id attr to the options so I can use that to store the index of Position.

    $.each(data.Company, function(i, v) {
        // create option with value as index - makes it easier to access on change
        var options = $('

    http://jsfiddle.net/wirey00/xYX8z/

提交回复
热议问题