在jQuery中获取SELECT的值和文本 [英] Get SELECT's value and text in jQuery

查看:269
本文介绍了在jQuery中获取SELECT的值和文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
获取所选选项标签的值在选择框中

Possible Duplicate:
Getting the value of the selected option tag in a select box

对于SELECT框,如何在jQuery中获取所选项目的值和文本?

For a SELECT box, how do I get the value and text of the selected item in jQuery?

例如,

<option value="value">text</option>

推荐答案

<select id="ddlViewBy">
    <option value="value">text</option>
</select>

jQuery

var txt = $("#ddlViewBy option:selected").text();
var val = $("#ddlViewBy option:selected").val();

JS Fiddle演示版

JS Fiddle DEMO

这篇关于在jQuery中获取SELECT的值和文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆