[removed] How to copy all options from one select element to another?

后端 未结 8 1440
有刺的猬
有刺的猬 2020-12-28 15:41

How can I copy all options of one select element to another? Please give me the easiest way, I\'m allergic to looping.

Please help me. Than

8条回答
  •  执念已碎
    2020-12-28 16:01

    One of the easiest ways without looping, is using jquery (select1 = id of select 1, select2 = id of select 2):

    $('#select1 option').clone().appendTo('#select2');
    

    Without jquery:

    var select1 = document.getElementById("select1");
    var select2 = document.getElementById("select2");
    select2.innerHTML = select2.innerHTML+select1.innerHTML;
    

提交回复
热议问题