获取选择选项标签的文本,并将其填充在隐藏的输入字段中 [英] Get text of select option's label and populate it in a hidden input field

查看:106
本文介绍了获取选择选项标签的文本,并将其填充在隐藏的输入字段中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取选择选项标签的文本并将其填充在隐藏的输入字段中.

I would like to Get text of select option's label and populate it in a hidden input field.

我可以得到的价值,但我想知道选择或更改选项时如何填充隐藏字段.我实际上是一名jQuery新手,所以我真的不知道与select选项相关的事件.

I can get the value but i would like to know how to populate the hidden field when option is selected or changed. I am actually a jquery newbie so i really have no idea of the event associated with select option.

推荐答案

小提琴: http://jsfiddle.net/m5A9U /

代码

假设您的HTML是

<select id="select">
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>    
</select>

<input type='hidden' id='hidden' value=''/>

jquery代码为

$("#select").change(function () {
    $("#hidden").val($(this).val());
    //alert($(this).val()) 
})

编辑要获取所选选项的标签,请尝试 $("#hidden").val($(this).find('option:selected').text());

EDIT To get the label of the selected option try $("#hidden").val($(this).find('option:selected').text());

更新后的示例: http://jsfiddle.net/m5A9U/1/

这篇关于获取选择选项标签的文本,并将其填充在隐藏的输入字段中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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