单击时在 javascript 中调用 url

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11577522/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 06:23:09  来源:igfitidea点击:

Call a url in javascript on click

javascriptjspurl

提问by being_uncertain

I have a javascript function. On-click will call this. Using document.getElementByIdI am getting certain parameters there. Using that parameters I need to build a url. ie, onclick will have to execute that url.

我有一个 javascript 函数。单击时将调用此方法。使用document.getElementById我在那里得到某些参数。使用该参数我需要构建一个 url。即,onclick 将必须执行该 url。

For example, in javascript,

例如,在 javascript 中,

function remove()
{
var name=...;
var age = ...;
// url should be like http://something.jsp?name=name&age=age
}

In short I need to execute http://something.jsp?name=name&age=agethis url on click

简而言之,我需要http://something.jsp?name=name&age=age在点击时执行这个网址

<input type="button" name="button" onclick="remove();" />

回答by Wouter J

Use window.location:

使用window.location

function remove()
{
    var name = ...;
    var age  = ...;

    window.location = 'http://something.jsp?name=' + name + '&age=' + age;
}

回答by Nick

I use:

我用:

document.location.href = "report.html";

So, in your case:

所以,在你的情况下:

function remove() {
    var name=... ,
        age = ...;

    document.location.href = "something.jsp?name=" + name + "&age=" + age;
}

回答by kommradHomer

just call

打电话

window.location=myURL;

in your function

在你的函数中