javascript - 从下拉列表中选择会导致页面在新窗口中打开
问题描述
我有一个使用 vb.net 的 asp.net 页面。有一个链接按钮可以在单独的选项卡中打开商店的网站。这是使用 Javascript 完成的。还有一个包含外套尺寸的下拉列表。下拉列表发回。
这是我遇到的问题。
用户单击链接按钮,将他带到单独选项卡中的商店网站。该商店的网站实际上确实出现在一个标签中。但是,“之后”用户执行此操作,如果用户从下拉列表中选择尺寸,则原始页面会在新选项卡中打开。这不应该发生。从下拉列表中选择外套尺寸不应导致原始页面在单击链接按钮后在新选项卡中打开。有人可以让我知道如何解决这个问题吗?提前致谢。
服务器代码如下。
Protected Sub DropDownList1_SelectedIndexChanged(sender As Object, e As System.EventArgs)
Dim size As String
size = DropDownList1.SelectedValue
End Sub
Protected Sub LinkButton1_Click(sender As Object, e As System.EventArgs)
Dim link As String
link = "http://"
link = link + "www.google.com"
Response.Redirect(link)
End Sub
页面代码如下。
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:DropDownList ID="DropDownList1" runat="server"
onselectedindexchanged="DropDownList1_SelectedIndexChanged" AutoPostBack="True">
<asp:ListItem>Sm</asp:ListItem>
<asp:ListItem>Med</asp:ListItem>
<asp:ListItem>Lg</asp:ListItem>
<asp:ListItem>XLg</asp:ListItem>
</asp:DropDownList>
<br /><br />
<asp:LinkButton ID="LinkButton1" runat="server"
onclick="LinkButton1_Click" OnClientClick="SetTarget();">LinkButton</asp:LinkButton>
</form>
</body>
<script type = "text/javascript">
function SetTarget() {
document.forms[0].target = "_blank";
}
</script>
</html>
解决方案
推荐阅读
- point-clouds - 使用 mpegg 压缩点云时出现意外结果
- r - dplyr case_when 使用多列时不返回预期结果
- c - malloc() 如何在穿孔堆中分配内存?
- c# - EmguCV PCACompute InputData - 将 VectorOfPoint 转换为 Mat
- python - 如何将所有分类结果打印到我的 GUI 上的文本小部件?
- firebase - CocoaPods 找不到 pod "FirebaseFirestore" 的兼容版本:
- sensors - 访问原始 SpO2、EDA、ECG 和温度数据
- swift - 关于在 Swift 中使用泛型类型扩展 Optional 的问题
- json - JSON 中的问题映射到 Flutter 中的格式
- reactjs - 使用 i18next 显示来自 api 的响应的标准方式是什么?