朋友们好这是我的代码:

<select id='first'>
  <option value='1'> First  </option>
  <option value='2'> Second </option>
  <option value='3'> Three  </option>
</select>

这是我的select2代码:

$("#first").select2();

Below is code for getting selected value.

$("#first").select2('val'); // It returns first,second,three.

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相关问答推荐

如果您的 Select 器对象无效,为什么 jQuery 不会炸弹?

如何 Select 具有特定文本的所有锚标记

在范围内设置文本

将 HTML5 Canvas 转换为要上传的文件?

如何使用 jQuery 搜索 JSON 树

一次替换多个字符串

为什么要两次声明 jQuery?

如何使用给定的 url 判断图像是否存在?

延迟后运行功能

JQuery html() 与 innerHTML

jquery beforeunload 关闭(不离开)页面时?

为什么找不到我的 json 文件?

如何触发href元素的点击事件

Jquery Ajax 错误处理忽略中止

带有 jquery 的 jsonp

在 jQuery 中 Select 后代元素的最快方法是什么?

只绑定一次事件

添加到数组 jQuery

如何使用 jQuery Select 第一个父 DIV?

粘性侧边栏:向下滚动时固定在底部,向上滚动时固定在顶部