如何在window.location.href中传递QueryString

How to Pass QueryString in window.location.href?

本文关键字:QueryString href location window      更新时间:2023-09-26

我已经编写了以下javascript函数

function getval(sel)
 {
    window.location.href = "Posts?Category=<%= sel %>";
 }

但是在querystring中没有考虑sel变量的值。。

取而代之的是,它的价值如下。

/张贴?类别=%3C%=%20sel%20%%3E

有人能帮我吗???

因为javascript不理解jsp scriptlet,

试试,

window.location.href = "Posts?Category=" + sel;

我不知道你在哪里找到这个<%= sel %>,但它不是原生的JavaScript风格。试试这个:

function getval(sel)
{
    window.location.href = "Posts?Category=" + sel;
 }