[英]onclick having href in a submit button
当我单击更新/提交按钮时,我想更改页面。 这是我的提交按钮代码:
<td width="8%"><input type="submit" name="submit" value="Update" onclick="??????????"></td>
我在要链接/ href的位置放置一个问号。 或者,您可以建议其他方法来执行此操作,当我单击“更新”按钮时,它会将我定向到另一个php文件。 谢谢!
无需onclick
。 onclick
用于执行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()">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.