真诚地说我正在使用tag-it,当我在其中添加值时,我会得到这样的ul
<ul id="mytags" class="tagit ui-widget ui-widget-content ui-corner-all">
<li class="tagit-choice ui-widget-content ui-state-default ui-corner-all tagit-choice-editable">
<span class="tagit-label">Android</span>
<a class="tagit-close"><span class="text-icon">×</span><span class="ui-icon ui-icon-close"></span></a>
</li>
<li class="tagit-choice ui-widget-content ui-state-default ui-corner-all tagit-choice-editable">
<span class="tagit-label">Java</span>
<a class="tagit-close"><span class="text-icon">×</span><span class="ui-icon ui-icon-close"></span></a>
</li>
<li class="tagit-new"><input type="text" class="ui-widget-content ui-autocomplete-input" autocomplete="off"></li>
</ul>
我想将li
动态添加options
添加到select
。我找到了一个例子jsFiddle
由于我没有任何JS世界的经验,我已将其更改为此jsfiddle但未获得结果,并且不会添加li
作为选择任何帮助的选项。
答案 0 :(得分:0)
你可以试试这个
<select id="yourSelect"></select>
<script>
var allItems = document.getElementById("mytags").children;
var i = 0;
var len = allItems.length;
var element;
for(; i<len; i++) {
element = document.createElement("option");
element.textContent = allItems[i].textContent.slice(1, -2);
document.getElementById("yourSelect").appendChild(element)
}
</script>