繁体   English   中英

使用多选 jquery 插件创建动态下拉框时出现问题

[英]issue while creating a dynamic dropdown box using multiselect jquery plugin

I am trying to make a dynamic select dropdown, I tried writing the code in javascript and jquery both but can't append the options in the dropdown. 当我尝试查看存储的内容时,会显示 Html select 代码以及所有选项。 我应该在其中添加或更改什么,以便将选项存储在正确的 position 中?

 lines=["B","C","D","E","F","G"]; $(document).ready(function(){ $("#select1").multiselect({ placeholder: 'Features' }); }); // var selectFir = document.getElementById("select1"); // for (var i = 0; i < firstLine.length; i++) { // var x = document.createElement("OPTION"), // txt = document.createTextNode(firstLine[i]); // x.appendChild(txt); // x.setAttribute("value", firstLine[i]); // selectFir.appendChild(x); // selectFir.insertBefore(x, selectFir.lastChild); // }console.log(selectFir); firstLine = lines[0]; // Calls function to generate drop downs using options above for(var i=0; i< firstLine.length;i++) { //creates option tag jQuery('<option/>', { value: firstLine[i], html: firstLine[i] }).appendTo('#select1'); } jQuery('#select1').multiselect('refresh');
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/multiselect/2.2.9/js/multiselect.min.js"></script> <select multiple id="select1"> <option value="A">A</option> </select>

 lines=["B","C","D","E","F","G"]; $(document).ready(function(){ $("#select1").multiselect({ placeholder: 'Features' }); }); // var selectFir = document.getElementById("select1"); // for (var i = 0; i < firstLine.length; i++) { // var x = document.createElement("OPTION"), // txt = document.createTextNode(firstLine[i]); // x.appendChild(txt); // x.setAttribute("value", firstLine[i]); // selectFir.appendChild(x); // selectFir.insertBefore(x, selectFir.lastChild); // }console.log(selectFir); firstLine = lines; // Calls function to generate drop downs using options above for(var i=0; i< firstLine.length;i++) { //creates option tag jQuery('<option/>', { value: firstLine[i], html: firstLine[i] }).appendTo('#select1'); } jQuery('#select1').multiselect('refresh');
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/multiselect/2.2.9/js/multiselect.min.js"></script> <select multiple id="select1"> <option value="A">A</option> </select>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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