如何将按钮重定向到我的另一个页面?

问题描述:

我一直在尝试这样的事情如何将按钮重定向到我的另一个页面?

<form action="formularz.html"><button class="repair__button" type="button">Formularz serwisowy</button></form> 

,但它不工作,没有什么happend当我点击这个按钮。 我在做什么错?

当然

中 “formularz.html” 是在相同的目录为 “index.html的”

+1

使用' Formularz serwisowy'代替。 –

删除type="button"。它仅适用于悬挂JavaScript的按钮。您需要提交按钮(默认类型)才能提交表单。


你真的应该使用一个链接,而不是为此形式。您可以使用CSS来使链接看起来像一个按钮。

使用type="submit"表单中的重定向页面:

看看这个:

<form action="formularz.html"><button class="repair__button" type="submit">Formularz serwisowy</button></form> 

更新2:

根据您的评论。表单动作会将数据发送到下一页。所以如果页面不会在formularz.html中相同的目录或正确的编码比它不会工作... <form action="">将刷新页面。如果您不想刷新发送数据的页面,请使用AJAX。这可能对您有所帮助...检查工作代码在snippest。

在第一个按钮,它会显示错误,因为formularz.html页面没有在网页上找到,并在第二个按钮,我把谷歌的网址。所以当你点击提交按钮时,数据将发送到谷歌。

<form action="http://www.google.com" method="post">   
 
     <button type="submit" value="Submit Form" id="btnSubmitForm"> Submit The Form</button> 
 
    </form>

重要:

结账这段代码在你的页面。在Snippest你不能因为没有权限为。

更改正常的按钮提交按钮

更改按钮样式,看起来像一个链接

.repair__button { 
 
    background: none!important; 
 
    border: none; 
 
    padding: 0!important; 
 
    font: inherit; 
 
    border-bottom: 1px solid #444; 
 
    cursor: pointer; 
 
} 
 
.repair__button:focus { 
 
    outline: 0; 
 
} 
 
.repair__button:active, 
 
.repair__button:hover { 
 
    color: blue; 
 
    border-bottom: 1px solid blue; 
 
}
<form action="formularz.html"> 
 
    <button class="repair__button" type="submit">Formularz serwisowy</button> 
 
</form>

+0

谢谢,现在它的工作原理 –

+0

它对我有用。如果您使用的是jQuery,请确保您没有阻止任何使用javascript的表单提交,例如$(“form”).submit(function(event){ event.preventDefault(); // return false; });' –

+0

“按照Quentin的建议将按钮样式更改为链接” - 这与我推荐的相反。 – Quentin