【问题标题】:how to get the value from dropdownlist in jQuery如何从jQuery中的下拉列表中获取值
【发布时间】:2011-06-14 10:48:53
【问题描述】:

我的网页中有一个下拉列表,我如何从它们的选定选项中获取值

喜欢

<select id="selme">
<option id="a" value="1">I need it</option>
</select>

当它选择时,我如何获得“我需要它”的值。

我不是在谈论属性“值”,我需要一个填充下拉列表选项标签的值

【问题讨论】:

    标签: javascript jquery html events drop-down-menu


    【解决方案1】:

    试试

    $("#selme").change(function(){
        $(this).find("option:selected").text();
    });
    

    查看working demo

    【讨论】:

    • ack,我正要写一个类似的答案,但你打败了我:)
    • 太复杂了,$('#selme').val();够漂亮!
    • 这不会在提到的上下文中获取正确的结果。这将影响值而不是文本。
    • @Andreyco .val() 不会得到“我需要它”字符串
    【解决方案2】:
    【解决方案3】:

    这是我刚刚为你制作的一个 jsfiddle http://jsfiddle.net/AqmZp/

    基本上它实际上只是 $("#selme").val();

    【讨论】:

      【解决方案4】:

      检查一下-->

      用于获取文本

      $("#selme").change(function(){
       $(this[this.selectedIndex]).text();
      });
      

      为了获得价值

      $("#selme").change(function(){
       $(this[this.selectedIndex]).val();
      });
      

      【讨论】:

        【解决方案5】:

        试试这个..

        $('#selme option:selected').text();

        【讨论】:

          【解决方案6】:
          $('#selme option:selected').html()
          

          【讨论】:

            猜你喜欢
            • 2014-06-19
            • 1970-01-01
            • 1970-01-01
            • 2011-04-19
            • 1970-01-01
            • 2023-03-27
            • 2020-08-11
            • 2013-02-28
            • 1970-01-01
            相关资源
            最近更新 更多