0

如何在事件函数的下拉列表中获取选定值的索引。这是我的代码。

function(data, event) {
    console.log(data);
    var k = self.selectedValue;
}

数据具有下拉列表中所有值的列表。但是如何获得它的索引。

4

3 回答 3

0

尝试这个:

var e = document.getElementById("controlID");
var strUservalue = e.options[e.selectedIndex].value;
var strUsertext = e.options[e.selectedIndex].text;
于 2013-05-29T12:23:13.310 回答
0

https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement 查找“选定索引”。

// return the index of the selected option
alert(select.selectedIndex); //select is your element
于 2013-05-29T12:23:15.653 回答
0

您可以使用

this.value对于选定的值

this.selectedIndex用于索引

于 2013-05-29T12:22:49.793 回答