javascript 如何在 window.location.href 中传递 QueryString?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17653110/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to Pass QueryString in window.location.href?
提问by Abhay Andhariya
I have written the following javascript function
我编写了以下 javascript 函数
function getval(sel)
{
window.location.href = "Posts?Category=<%= sel %>";
}
but the value of sel variable is not considered in querystring..
但是在查询字符串中不考虑 sel 变量的值..
Instead of it, it takes value like following.
而不是它,它需要像下面这样的值。
...../Post/Posts?Category=%3C%=%20sel%20%%3E
...../帖子/帖子?类别=%3C%=%20sel%20%%3E
Can anyone help me???
谁能帮我???
回答by commit
Because javascript does not understands jsp scriptlet,
因为javascript不理解jsp scriptlet,
Try,
尝试,
window.location.href = "Posts?Category=" + sel;
回答by Matthias Tylkowski
I don't know where you found this <%= sel %>
, but its not the native JavaScript style of doing it. Try this:
我不知道你在哪里找到的<%= sel %>
,但它不是原生的 JavaScript 风格。试试这个:
function getval(sel)
{
window.location.href = "Posts?Category=" + sel;
}
回答by AMAN BIRDI
in Posts.html page add the code:
在 Posts.html 页面添加代码:
var queryString = location.search;
var Category = queryString[0];