简体   繁体   中英

Dynamically (programatically) add new options to dropkick <select> tag in jQuery

I am trying to dynamically add options to select tag in jQuery. This jQuery code below works fine.

select.append("<li>opt4</li>");

However, when I hover over options, it doesn't highlight any of options and when I select one option, it doesn't change the selected option.

To dynamically add options to the select, you should do as follows:

$(document).ready(function(){
    var select = new Dropkick("#dropdown");
    select.add("New Option", 2);
}); 

Here is the reference documentation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM