【问题标题】:Get text and value of dropdown list using jquery使用jquery获取下拉列表的文本和值
【发布时间】:2016-03-26 19:50:34
【问题描述】:

我在 asp.net mvc 5 的视图中有 4 个下拉列表,我想获取每个选择标记的文本和值以发送到我使用下面的代码执行的操作,但每次我获得第一个下拉列表的文本和值时

<select id="se1" class="mySelect" onchange="f22()">
        <option value="@item.ID">1</option>
        <option value="@item.ID">2</option>
        <option value="@item.ID">3</option>
        <option value="@item.ID">4</option>
        <option value="@item.ID">5</option>
</select>
<script src="~/Scripts/jquery-1.9.1.js"></script>

<script>
    function f22() {
        var a = $("#se1 option:selected").text();
        var b = $("#se1 option:selected").val();
        alert(a)
        alert(b)
    }
</script>

【问题讨论】:

  • 你能解释一下你的描述(问题)吗?

标签: jquery select text get


【解决方案1】:

使用this 作为f22 函数的参数将元素传递给js 函数,然后在js 中使用它,如下所示。希望这会对你有所帮助。

<select id="se1" class="mySelect" onchange="f22(this)">
    .........
    .........
</select>

function f22(elm) {
    var a = $(elm).find("option:selected").text();
    var b = $(elm).val();
    alert(a)
    alert(b)
}

【讨论】:

    猜你喜欢
    • 2013-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-18
    • 2013-06-15
    • 2023-03-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多