我怎样才能让一个按钮重定向我的网页到另一个页面? [英] How can I make a button redirect my page to another page?

查看:93
本文介绍了我怎样才能让一个按钮重定向我的网页到另一个页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



 < form action =/ homeclass =inline> 
< button class =float-left submit-button>主页< / button>
< / form>

它似乎可行,但会转到页面/ home?。



有没有更好的方式让我在表单中制作一个按钮让页面进入新的位置?

解决方案只要在按钮中添加一个 onclick 事件:

 < button onclick =location.href ='www.yoursite.com'; id =myButtonclass =float-left submit-button>主页< / button> 

但是你不应该像这样内联,而是把它放在JS块中,给出按钮一个ID:

 < button id =myButton class =float-left submit-button>主页< / button> 

< script type =text / javascript>
document.getElementById(myButton)。onclick = function(){
location.href =www.yoursite.com;
};
< / script>


I have been trying the following:

<form action="/home" class="inline">
    <button class="float-left submit-button" >Home</button>
</form>

It seems to work but it goes to the page "/home?"

Is there a better way for me to make a button inside a form make the page go to a new location?

解决方案

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>

这篇关于我怎样才能让一个按钮重定向我的网页到另一个页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆