如何在asp.net中使用javascript从ajax组合框中获取选定的值#

时间:2017-06-29 12:20:52

标签: javascript c# jquery asp.net ajax

我想在asp.net c#

中使用javascript从ajax组合框选择的项目中获取所选值

这是我的代码

tr

在警告中显示未定义。

请帮我解决这个错误

谢谢。

2 个答案:

答案 0 :(得分:0)

如果你可以使用jquery,你可以这样做:

<asp:ComboBox ID="dropdown_dest" runat="server" Width="90%" onfocusout="blurFunction()" AutoCompleteMode="SuggestAppend" CssClass="ComboboxWidth" DropDownStyle="DropDownList" Height="15px" MaxLength="50">
</asp:ComboBox>

function blurFunction()
{
    var ddlReport = $("#" + "<%=dropdown_dest.ClientID%>").find("option:selected").val();
    alert(ddlReport);
}

答案 1 :(得分:0)

我还没有测试过。

<asp:ComboBox ID="dropdown_dest" runat="server" Width="90%" onfocusout="blurFunction(this)" AutoCompleteMode="SuggestAppend" CssClass="ComboboxWidth" DropDownStyle="DropDownList" Height="15px" MaxLength="50">
</asp:ComboBox>

<script>

function blurFunction(e) {
var val = e.options[e.selectedIndex].value;
console.log(val);
}
</script>

使用“this”将跳过jquery循环,js脚本可以放在单独的文件中。

相关问题