jQuery获取选择选项ID并更改隐藏的输入值 [英] jQuery get select option id and change hidden input value

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

问题描述

我有一个带有选择列表的表格.每个选项还包含一个动态ID,我需要捕获它,然后使用它来更改隐藏输入的值.因此,基本上获取选定的选项id并更改隐藏输入值的值.

I have a form with a select list. Each option also contains a dynamic id, which I need to capture and then use that to change a hidden input's value. So basically take the selected options id and change the value of a hidden input value.

我的选择和隐藏输入看起来像:

My select and hidden input look like:

<select name="item_options" id="size">
<option value="20030" id="Universal">Universal (20030)</option>
<option value="4545456" id="Medium">Medium (4545456)</option>
<option value="15447" id="Large">Large (15447)</option>
</select>

<input type="hidden" name="item_options_name" value="Universal" id="changevalue" />

我做了一些jQuery来捕获所选选项的ID,但是我不知道如何使用它来更改输入值.

I had done some jQuery to capture the selected option's id, but I can't figure out how to use it to change my input's value.

推荐答案

$('#size').change(function(){
   var id = $(this).find(':selected')[0].id;
   $('#changevalue').val(id);
})

这篇关于jQuery获取选择选项ID并更改隐藏的输入值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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