Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/414.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从dropdownlist中选择会导致页面在新窗口中打开_Javascript_Asp.net_Vb.net - Fatal编程技术网

Javascript 从dropdownlist中选择会导致页面在新窗口中打开

Javascript 从dropdownlist中选择会导致页面在新窗口中打开,javascript,asp.net,vb.net,Javascript,Asp.net,Vb.net,我有一个使用vb.net的asp.net页面。有一个链接按钮,可以在单独的选项卡中打开商店的网站。这是使用Javascript完成的。还有一个下拉列表,其中包含外套尺寸。下拉列表返回 这就是我遇到的问题 用户单击linkbutton,在单独的选项卡中将他带到商店的网站。事实上,这家商店的网站确实出现在了一个标签上。但是,在用户执行此操作之后,如果用户从下拉列表中选择一个大小,则原始页面将在新选项卡中打开。这不应该发生。从下拉列表中选择涂层尺寸不应导致在单击链接按钮后在新选项卡中打开原始页面。有人

我有一个使用vb.net的asp.net页面。有一个链接按钮,可以在单独的选项卡中打开商店的网站。这是使用Javascript完成的。还有一个下拉列表,其中包含外套尺寸。下拉列表返回

这就是我遇到的问题

用户单击linkbutton,在单独的选项卡中将他带到商店的网站。事实上,这家商店的网站确实出现在了一个标签上。但是,在用户执行此操作之后,如果用户从下拉列表中选择一个大小,则原始页面将在新选项卡中打开。这不应该发生。从下拉列表中选择涂层尺寸不应导致在单击链接按钮后在新选项卡中打开原始页面。有人能告诉我怎么解决这个问题吗?提前谢谢

下面是服务器代码

<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>
Protected Sub-DropDownList1\u SelectedIndexChanged(发送方作为对象,e作为System.EventArgs)
像字符串一样变暗
大小=下拉列表1.SelectedValue
端接头
受保护的子链接按钮1\u单击(发件人作为对象,e作为System.EventArgs)
将链接设置为字符串
link=“http://”
link=link+“www.google.com”
响应.重定向(链接)
端接头
页面代码如下

<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>

钐
医学
Lg
XLg


链接按钮 函数SetTarget(){ document.forms[0]。target=“\u blank”; }
我认为这是因为您将表单[0]的目标设置为
\u blank
单击链接按钮后,任何后续的回发(如选择dropdownlist项)都将在新选项卡中打开。您是否必须再次单击设置URL?如果没有,只需使用
超链接
控件并设置其
目标
属性,而不是表单的属性。