如何在 choosen.js 下拉列表中获取选定的文本值
How to get selected Text Value in choosen.js dropdown list
我在使用 choosen.js 的下拉列表中遇到问题。
我在 MaterialName 下拉列表中有这个列表:
Material名称 //id ="drpMaterial"
MaterialName1 //id="1" Text="MaterialName1"
MaterialName2 //id="2" Text="MaterialName2"
MaterialName3 //id="3" Text="MaterialName2"
这是我的逻辑:
每次我选择一个 Material 名称时,我都会得到 id 并在另一个文本字段中输入 StockNo 并且我希望将 text 添加到我的 数据表中。
现在的问题是每次我得到 $("#drpMaterial").text() 我得到三(3)个列表该:
MaterialName1
MaterialName2
MaterialName3
我想要的就是我选择的那个
这是我的代码,我现在只想 alert 我在 Material 下拉列表中选择的 text:
$(".chosen-select").chosen({
allow_single_deselect: true,
display_selected_options: false,
single_backstroke_delete: false,
search_contains: true
});
$("#drpMaterial").change(function () {
alert($("#drpMaterial").text());
$("#StockNo").val($("#drpMaterial").val());
});
请帮忙...谢谢。
$("#drpMaterial option:selected").text()
Description: Selects all elements that are selected.
使用 option:selected
到 select selected 选项的文本
我在使用 choosen.js 的下拉列表中遇到问题。
我在 MaterialName 下拉列表中有这个列表: Material名称 //id ="drpMaterial"
MaterialName1 //id="1" Text="MaterialName1"
MaterialName2 //id="2" Text="MaterialName2"
MaterialName3 //id="3" Text="MaterialName2"
这是我的逻辑:
每次我选择一个 Material 名称时,我都会得到 id 并在另一个文本字段中输入 StockNo 并且我希望将 text 添加到我的 数据表中。
现在的问题是每次我得到 $("#drpMaterial").text() 我得到三(3)个列表该:
MaterialName1
MaterialName2
MaterialName3
我想要的就是我选择的那个
这是我的代码,我现在只想 alert 我在 Material 下拉列表中选择的 text:
$(".chosen-select").chosen({
allow_single_deselect: true,
display_selected_options: false,
single_backstroke_delete: false,
search_contains: true
});
$("#drpMaterial").change(function () {
alert($("#drpMaterial").text());
$("#StockNo").val($("#drpMaterial").val());
});
请帮忙...谢谢。
$("#drpMaterial option:selected").text()
Description: Selects all elements that are selected.
使用 option:selected
到 select selected 选项的文本