使用JQuery获取SELECT的选定选项文本

问题描述 投票:0回答:2

我已经动态创建了选项,其中选项中的所有值都来自共享点列表。现在我想获取所选选项的文本。我尝试了几种方法,但无法获得

从列表中获取数据的代码

$("#ddlIncrementType").append(
  $("<option></option>")
    .data("incrementLevel", results[increment].IncrementLevel)
    .val(results[increment].Title)
    .html(results[increment].Title)
);

我的选项所附的代码

<div class="Increment">
    <label for="sel1">Increment Type:</label>
    <select disabled class="form-control" id="ddlIncrementType">
        <option></option>
    </select>
</div>

我想获取选定选项的文本假设列表中有三个选项

  1. 第一项
  2. 第二项
  3. 项目三

我想要确切的文字谁能帮忙?

我尝试过,但是没有用!

var value = $("#ddlIncrementType").find(":selected").val();

var selectedText = $("#mySelect option:selected").html();

var value = $("#ddlIncrementType").find(":selected").text();
javascript jquery sharepoint-2010
2个回答
0
投票

您可以使用-

$(document).on('change', "#ddlIncrementType", function(){
    var value = $(this).text();
    alert(value);
});

而且您不应该将disabled用作<select>


0
投票

您可以尝试:

$("#ddlIncrementType option:selected").text();
© www.soinside.com 2019 - 2024. All rights reserved.