jQuery select2获取选择标签的值? [英] jQuery select2 get value of select tag?
本文介绍了jQuery select2获取选择标签的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
朋友您好,这是我的代码:
Hello friends this is my code:
<select id='first'>
<option value='1'> First </option>
<option value='2'> Second </option>
<option value='3'> Three </option>
</select>
这是我的select2代码:
This is my select2 code:
$("#first").select2();
下面是用于获取所选值的代码.
Below is code for getting selected value.
$("#first").select2('val'); // It returns first,second,three.
这是返回类似first,second,three
的文本,我想获取1,2,3
.
意味着我需要选择框的值,而不是文本.
This is return a text like first,second,three
and I want to get 1,2,3
.
Means I need the value of select box, not text.
推荐答案
$("#first").val(); // this will give you value of selected element. i.e. 1,2,3.
这篇关于jQuery select2获取选择标签的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文