Adding options to a <select> using jQuery?

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

    We found some problem when you append option and use jquery validate. You must click one item in select multiple list. You will add this code to handle:

    $("#phonelist").append("");
    
    $("#phonelist option:selected").removeAttr("selected"); // add to remove lase selected
    
    $('#phonelist option[value=' + 'yournewvalue' + ']').attr('selected', true); //add new selected
    

提交回复
热议问题