1

如何使用jquery找到当前选择的选项的位置,如果用户选择不同的选项也需要实时更新。

 <select id="visa_type_c" title="" name="visa_type_c">
     <option selected="selected" value="No Visa" label="No Visa">No Visa</option>
     <option value="EU Visa" label="EU Visa">EU Visa</option>
     <option value="Easy Visa" label="Easy Visa">Easy Visa</option>
     <option value="Hard Visa" label="Hard Visa">Hard Visa</option>
 </select>

我看到了其他线程,但它们略有不同,我似乎无法让它适合我。

4

3 回答 3

7

可以只使用纯JS:

document.getElementById("visa_type_c").onchange = function() {
    alert(this.selectedIndex);
}

纯 JS 演示:http: //jsfiddle.net/Xxqnr/1/

于 2013-08-14T12:59:50.227 回答
6
$("select").on("change", function(ev) {
    console.log(ev.target.selectedIndex);
});
于 2013-08-14T13:00:47.243 回答
1
<a href='javascript:alert($("#visa_type_c option:selected").index())';>click for index</a>

很多方法可以做到这一点;如果您将此添加到您的页面,它将显示您选择的索引。

于 2013-08-14T13:39:09.343 回答