如何在jQuery中获得$(this)选择的选项? [英] How to get $(this) selected option in jQuery?
本文介绍了如何在jQuery中获得$(this)选择的选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下代码有效:
$("#select-id").change(function(){
var cur_value = $('#select-id option:selected').text();
. . .
});
如何将第二行重构为:
var cur_value = $(this).***option-selected***.text();
***option-selected***
的用途是什么?
推荐答案
对于所选值:$(this).val()
如果需要选定的选项元素,请$("option:selected", this)
If you need the selected option element, $("option:selected", this)
这篇关于如何在jQuery中获得$(this)选择的选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文