首页 > 解决方案 > onClick="window.location='/viewAllAdmins';" 正在提交表单而不是转发到提供的链接

问题描述

<table border=0 align=center cellpadding=9>
<tr>
<td>
<button class="font-awesome-btn" onClick="window.location='/viewAllAdmins';"  style="margin:auto; display:block;"><i class="fa fa-arrow-left" aria-hidden="true"></i>  Go Back  </button>
</td>
<td>
<button class="font-awesome-btn"> Submit <i class="fa fa-arrow-right" aria-hidden="true"></i></button>
</td>
</tr></table>

onClick 事件提交表单,而不是将我带到提供的 URL。

标签: htmlcss

解决方案


那是因为您的按钮是提交按钮,并且您没有取消其默认操作。您可以设置type="button"为简单地解决这个问题。


但是使用按钮首先是对那个元素的“滥用”——如果你只是想链接到其他地方——那么你应该使用链接,<a>. 如果需要,通过 CSS将其格式化为看起来像一个按钮。


推荐阅读