Adding options to a <select> using jQuery?

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

    Option 1-

    You can try this-

    $('#selectID').append($('

    Like this-

    for (i = 0; i < 10; i++)
    { 
         $('#mySelect').append($('
    
    
    

    Option 2-

    Or try this-

    $('#selectID').append( '' );
    

    Like this-

    for (i = 0; i < 10; i++)
    { 
         $('#mySelect').append( '' );
    }
    
    
    

提交回复
热议问题