【问题标题】:Call a url in javascript on click点击时在javascript中调用一个url
【发布时间】:2012-07-20 10:28:31
【问题描述】:

我有一个 javascript 函数。点击会调用这个。使用document.getElementById 我在那里得到了某些参数。使用该参数,我需要构建一个 url。即,onclick 必须执行该 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这个url

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

【问题讨论】:

    标签: javascript jsp url


    【解决方案1】:

    使用window.location:

    function remove()
    {
        var name = ...;
        var age  = ...;
    
        window.location = 'http://something.jsp?name=' + name + '&age=' + age;
    }
    

    【讨论】:

      【解决方案2】:

      我用:

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

      所以,在你的情况下:

      function remove() {
          var name=... ,
              age = ...;
      
          document.location.href = "something.jsp?name=" + name + "&age=" + age;
      }
      

      【讨论】:

        【解决方案3】:

        打个电话

        window.location=myURL;
        

        在你的函数中

        【讨论】:

          猜你喜欢
          • 2016-09-15
          • 2019-08-07
          • 1970-01-01
          • 2016-03-09
          • 2012-11-24
          • 2016-11-11
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多