我有两个下拉列表,它们都列出了相同的国家/地区。我想当用户在两个下拉列表中选择相同的国家/地区时显示一条警报消息。我怎样才能使用 jQuery 做到这一点?
<td>
<asp:DropDownList ID="ddlCountry" runat="server" AutoPostBack="True">
</asp:DropDownList>
</td>
<td>
<asp:DropDownList ID="ddlCountry1" runat="server" AutoPostBack="True">
</asp:DropDownList>
</td>
<script type="text/javascript">
$(document).ready(function () {
$("#<%=ddlCountry.ClientID %>").change(function () {
if ($("#<%=ddlCountry.ClientID%> option:selected").text() == $("#<%=ddlCountry1.ClientID%> option:selected").text())
{
alert("Please select different countries");
}
});
});
</script>
最佳答案
问题是您的下拉列表将自动回发设置为 true。
关于javascript - 如何使用 jquery 在 C# 中显示警报框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25539663/