Adding options to a <select> using jQuery?

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

    You can add options dynamically into dropdown as shown in below example. Here in this example I have taken array data and binded those array value to dropdown as shown in output screenshot

    Output:

    var resultData=["Mumbai","Delhi","Chennai","Goa"]
    $(document).ready(function(){
       var myselect = $('
    
    

提交回复
热议问题