如何使用jquery抓取并发送下拉列表的显示文本而不是值 [英] How do I grab and send a dropdown's display text instead of value using jquery

查看:72
本文介绍了如何使用jquery抓取并发送下拉列表的显示文本而不是值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用这部分jquery将从下拉列表中选择的值放入隐藏的文本字段中.效果很好-在论坛上的某个人那里得到了它!!!!但是,我在代码中遇到了一些麻烦,我需要做同样的事情,但是这次我很乐意发送 Display向我将创建的另一个隐藏文件发送文本.使用此代码,我将进行哪些更改以获取显示文本,而不是相关的值. 例如,如果我有

I am using this bit of jquery to put the value selected from my dropdown into a hidden text field. This works beautifully - got it from one of the folks on this forum!!!, but I just ran into a twist further in my code and I need to do the same thing, but this time I neeed to send the Display Text to another hidden filed that I will create. Using this code, what do I change to grab the display text instead of the associated value. for example if I have:

<select id="firstbox">
<option value="TM">Time Warner</option>
<option value="CC">Comcast</option>
<option value="HC">Hartford Cable</option>
</select>

如何更改下面的代码以获取并发送时代华纳",康卡斯特"或哈特福德电缆"?

$(document).ready(function() {
        $("select#2135, select#4436, select#4437").change(function(){
            $("#4443").val($(this).val());
        })
        .trigger('change');
    });

推荐答案

在所选选项上使用.text()代替.val()

Use .text() instead of .val() on the selected option

$(this).find(":selected").text()


ids也应该以字母开头


ids should start with a letter, too

这篇关于如何使用jquery抓取并发送下拉列表的显示文本而不是值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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