jQuery从下拉菜单中选择选项 [英] jQuery Get Selected Option From Dropdown

查看:98
本文介绍了jQuery从下拉菜单中选择选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常我使用 $(#id).val()来返回所选选项的值,但这次不起作用。
所选标记的ID aioConceptName

Usually I use $("#id").val() to return the value of the selected option, but this time it doesn't work. The selected tag has the id aioConceptName

html代码 p>

html code

<label>Name</label>
<input type="text" name="name" />
<select id="aioConceptName">
    <option>choose io</option>
    <option>roma</option>
    <option>totti</option>
</select>


推荐答案

对于下拉选项,您可能需要如下所示:

For dropdown options you probably want something like this:

var conceptName = $('#aioConceptName').find(":selected").text();

原因 val()不会诀窍是因为点击一个选项不会改变下拉列表的值 - 它只是将:selected 属性添加到选择的选项中,该选项是一个子选项的下拉列表。

The reason val() doesn't do the trick is because clicking an option doesn't change the value of the dropdown--it just adds the :selected property to the selected option which is a child of the dropdown.

这篇关于jQuery从下拉菜单中选择选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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