gpt4 book ai didi

javascript - 在 asp 中将变量传递给 javascript 函数失败 :dropdownlist

转载 作者:行者123 更新时间:2023-11-28 19:34:18 24 4
gpt4 key购买 nike

目前我有一个按以下方式调用的函数:

<script type="text/javascript">
getCities('<%=BusinessID %>');
</script>

这没有任何问题,现在我想对 asp:dropdownlist 中的 onchange 事件执行相同的操作,如下所示:

<asp:DropDownList ID="ddlAddressSPC" runat="server" clientidmode="Static" AutoPostBack="False" onchange="javascript:getCities('<%=BusinessID %>');" Width="306px" CssClass="txt12NormalLeft" ToolTip="Select State|Province|County" />

但现在 ASP.net 变量不会被评估,而是作为 <%=BusinessID %> 而不是值传递。

如果我在正常的 HTML 选择中执行相同的代码,那么这不是问题。我在这里缺少什么?

最佳答案

您不能直接在服务器元素标记上执行此操作。

您应该在后面的代码中执行此操作:

ddlAddressSPC.Attributes.Add("onchange", "javascript:getCities('" + BusinessID + "');");

关于javascript - 在 asp 中将变量传递给 javascript 函数失败 :dropdownlist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26215739/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com