获取选择标记中的列表项

时间:2015-09-17 11:52:48

标签: javascript sharepoint

如何在select标签中获取列表项?我尝试了很多不同的方法,但没有任何效果。 我的代码:

<select id ="listBox" multiple="multiple" style="width:200px; height:400px;">
    <option></option>
</select>

function onSuccess1() {
var lstBox= document.getElementById('listBox'); 

lstBox.options.length = 0;

var listEnumerator = listItems.getEnumerator();

while (listEnumerator.moveNext()) {

    var currentItem = listEnumerator.get_current();
    var listBoxItems = currentItem.get_item("Title");
    lstBox.options[lstBox.options.length] = new Option(listBoxItems, currentItem.get_item("Title"));
}

1 个答案:

答案 0 :(得分:1)

老实说,我没有得到你的代码所以这里就像它一般的工作:

function add()
{
  var select = document.getElementById ("my_select");
  var o = document.createElement("option");
  o.text = "New Option";
  select.add (o);
}
Click the button to add an option to the select list.
<br>
<select id="my_select">
</select>
<input type="submit" onclick="add();" value="Add another option" />

相关问题