Adding options to a <select> using jQuery?

后端 未结 30 2378
萌比男神i
萌比男神i 2020-11-22 03:56

What\'s the easiest way to add an option to a dropdown using jQuery?

Will this work?

$(\"#mySelect\").append(\'
30条回答
  •  梦谈多话
    2020-11-22 04:30

    Personally, I prefer this syntax for appending options:

    $('#mySelect').append($('

    If you're adding options from a collection of items, you can do the following:

    $.each(items, function (i, item) {
        $('#mySelect').append($('

提交回复
热议问题