【问题标题】:How to redirect to an other webpage onclicking on input如何在点击输入时重定向到另一个网页
【发布时间】:2012-11-15 06:55:47
【问题描述】:

我有一个按钮类型的输入:

<input type='button' value='Click me' />

我需要在点击时重定向。

提前致谢。

【问题讨论】:

  • 除了重定向之外还需要做什么吗?是否需要传输任何表单数据?或者这只是一个应该是链接的按钮?
  • 不,这是一个按钮,因为设计基于按钮

标签: javascript html dom


【解决方案1】:

html:

 <input type='button' id="myBtn" value='Click me' />

js:

var btn = document.getElementById('myBtn');
btn.onclick = function(){
   window.location = "http://stackoverflow.com/";
}

别忘了window.onload

【讨论】:

    【解决方案2】:

    选项 1:

    改用链接标签

    <a href="other_site">Click Me</a>
    

    并通过 CSS 使元素看起来像按钮。

    选项 2:

    <input type="button" value="Click Me" 
           onclick="window.location='http://www.example.org';" />
    

    【讨论】:

      猜你喜欢
      • 2021-06-09
      • 2021-05-10
      • 2015-12-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多