我搜索了相关帖子,但所有尝试均无效。
我的问题是,我正在尝试使用 path+querystring 在 Javascript 中进行简单的重定向。我的代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Page1.aspx.cs" Inherits="WebApplication1.Page1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="submit" value="pesq" onclick="Redirect();"/>
</div>
</form>
<script>
function Redirect()
{
window.location.href = 'http://localhost:61267/Page1.aspx?q=name';
}
</script>
</body>
</html>
window.location.href 始终设置为 'http://localhost:61267/Page1.aspx'
。
我尝试过使用 window.location.search 但仍然没有成功。
我做错了什么?
最佳答案
改用 document.location。
document.location = 'http://localhost:61267/Page1.aspx?q=name';
关于javascript - 使用 window.location 重定向不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27725127/