jQuery获取选定的选项值(不是文本,而是属性'值') [英] jQuery get selected option value (not the text, but the attribute 'value')

查看:126
本文介绍了jQuery获取选定的选项值(不是文本,而是属性'值')的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我有这样的代码:

 < select name =selectorid =selector> 
< option value =1>选项1< / option>
< option value =2>选项2< / option>
< / select>

我想要选择选项的值。
示例:
'选项2'被选中,其值为'2'。 '2'是我需要得到的值,而不是'Option 2'。 使用 .val 以获取所选选项的值。见下面,

  $('select [name = selector]')。val()


Okay, I have this code:

<select name="selector" id="selector">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
</select>

And I'd like to get the value of the option selected. Example: 'Option 2' is selected, and the value of it is '2'. The '2' is the value I need to get and not 'Option 2'.

解决方案

Use .val to get the value of the selected option. See below,

$('select[name=selector]').val()

这篇关于jQuery获取选定的选项值(不是文本,而是属性'值')的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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