html - 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。
解决方案
那是因为您的按钮是提交按钮,并且您没有取消其默认操作。您可以设置type="button"
为简单地解决这个问题。
但是使用按钮首先是对那个元素的“滥用”——如果你只是想链接到其他地方——那么你应该使用链接,<a>
. 如果需要,通过 CSS将其格式化为看起来像一个按钮。
推荐阅读
- python - 为什么熊猫会违反自己的警告?
- python - 使用pandas按列分组,然后根据条件新建一列
- android - Android Studio上的gradle项目同步失败错误
- c# - 如何处理 Controller 的 Initialize 方法抛出的异常?
- tensorflow - LSTM 或任何其他层的 TimeDistributed 包装器有什么用途
- assertion - 如何在 Junit 中使用 Assert array Equals 比较 2 个对象数组
- php - 更改会话目录 PHP
- python - 为 n 维数组推广 Cython 代码
- javascript - 需要创建一个新数组而不是为我的 React 组件推送数据
- javascript - Vue js 事件中的命名空间