Onclick中有一个提交按钮

onclick having href in a submit button

本文关键字:按钮 提交 有一个 Onclick      更新时间:2023-09-26

我想在点击更新/提交按钮时更改页面。这是我的提交按钮代码:

<td width="8%"><input type="submit" name="submit" value="Update" onclick="??????????"></td>

我在我想要链接/href的地方放一个问号。或者你可以建议其他方法当我点击更新按钮时,它会引导我到另一个php文件。谢谢!

不需要onclickonclick用于执行JS。这是通过为<form>设置action属性来完成的。

<form method="POST" action="anotherPHPFile.php">
     <input type="submit" name="submit" value="Update">
</form>

点击按钮后,您将被重定向到anotherPHPFile.php

这样做!

function redirect(e){
//If you want to check something here can prevent defualt button action
   // e.preventDefault()
//now do your action.
// similar behavior as an HTTP redirect
window.location.replace("http://stackoverflow.com");
// you can also use this line to do similar behavior as clicking on a link
// window.location.href = "http://stackoverflow.com";
}
<input type="submit" name="submit" value="Update" onclick="redirect()">