【发布时间】:2012-11-15 06:55:47
【问题描述】:
我有一个按钮类型的输入:
<input type='button' value='Click me' />
我需要在点击时重定向。
提前致谢。
【问题讨论】:
-
除了重定向之外还需要做什么吗?是否需要传输任何表单数据?或者这只是一个应该是链接的按钮?
-
不,这是一个按钮,因为设计基于按钮
标签: javascript html dom
我有一个按钮类型的输入:
<input type='button' value='Click me' />
我需要在点击时重定向。
提前致谢。
【问题讨论】:
标签: javascript html dom
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
【讨论】:
选项 1:
改用链接标签
<a href="other_site">Click Me</a>
并通过 CSS 使元素看起来像按钮。
选项 2:
<input type="button" value="Click Me"
onclick="window.location='http://www.example.org';" />
【讨论】: