How can I make a button redirect my page to another page?
This question already has an answer here:
Just add an onclick
event to the button
:
<button onclick="location.href = 'www.yoursite.com';" id="myButton" class="float-left submit-button" >Home</button>
But you shouldn't really have it inline like that, instead, put it in a JS block and give the button
an ID:
<button id="myButton" class="float-left submit-button" >Home</button>
<script type="text/javascript">
document.getElementById("myButton").onclick = function () {
location.href = "www.yoursite.com";
};
</script>
尝试
<button onclick="window.location.href='b.php'">Click me</button>
只是另一种变化:
<body>
<button name="redirect" onClick="redirect()">
<script type="text/javascript">
function redirect()
{
var url = "http://www.(url).com";
window.location(url);
}
</script>
链接地址: http://www.djcxy.com/p/36552.html
上一篇: 如何链接两个HTML页面和一个按钮?