Adding options to a <select> using jQuery?

后端 未结 30 2377
萌比男神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:14

    If you want to insert the new option at a specific index in the select:

    $("#my_select option").eq(2).before($('

    This will insert the "New Item" as the 3rd item in the select.

提交回复
热议问题