簡體   English   中英

如何在下拉列表中獲取選定值的索引javascript

[英]How to get index of selected value in Dropdown list javascript

如何在事件函數的下拉列表中獲取選定值的索引。 這是我的代碼。

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

數據具有“下拉列表”中所有值的列表。 但是如何獲得它的索引。

您可以使用

this.value選定值

this.selectedIndex用於索引

嘗試這個:

var e = document.getElementById("controlID");
var strUservalue = e.options[e.selectedIndex].value;
var strUsertext = e.options[e.selectedIndex].text;

https://developer.mozilla.org/zh-CN/docs/Web/API/HTMLSelectElement查找“選定的索引”。

// return the index of the selected option
alert(select.selectedIndex); //select is your element

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM