2012-07-20 35 views
6

我有一個javascript函數。點擊就會打電話給這個。使用document.getElementById我在那裏得到某些參數。使用這個參數我需要建立一個url。即,onclick將不得不執行該網址。點擊javascript調用url

例如,在JavaScript中,

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

總之我需要執行http://something.jsp?name=name&age=age這個網址上點擊

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

回答

7

使用window.location

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

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

我用:

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

所以,你的情況:

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

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