如何使用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>
Run Code Online (Sandbox Code Playgroud)
我看到了其他线程,但它们略有不同,我似乎无法让它适合我.
可以只使用纯JS:
document.getElementById("visa_type_c").onchange = function() {
alert(this.selectedIndex);
}
Run Code Online (Sandbox Code Playgroud)
纯JS演示:http://jsfiddle.net/Xxqnr/1/
$("select").on("change", function(ev) {
console.log(ev.target.selectedIndex);
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4217 次 |
| 最近记录: |