HTML5表单按钮onsubmit不起作用 [英] HTML5 form button onsubmit not working
本文介绍了HTML5表单按钮onsubmit不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有两个HTML5按钮的简单表单.每个按钮将表单提交到不同的php页面.这运行良好,但是从未触发过"onsubmit"功能.我想在调用delete.php页面之前显示一个对话框.
I have a simple form with two HTML5 buttons. Each button submits the form to a different php page. This is working well, but the 'onsubmit' function is never triggered. I want to show a dialog box before the delete.php page is called.
<form method="post">
<input type="text" name="fname">
<!-- HTML5 FORMACTION -->
<button type="submit" name="update" formaction="update.php">Update</button>
<button type="submit" name="delete" onsubmit="return confirm('Do you really want to delete?');" formaction="delete.php">Delete</button>
</form>
我尝试了不同的变体,但是javascript代码从未触发.为什么?
I have tried different variations, but the javascript code is never triggered. Why?
推荐答案
尝试这样
<form method="post">
<input type="text" name="fname">
<!-- HTML5 FORMACTION -->
<button type="submit" name="update" formaction="update.php">Update</button>
<button type="button" name="delete" onclick="return delete();" formaction="delete.php">Delete</button>
</form>
<script>
function delete(){
if(confirm('Do you really want to delete?')){
// delete code
}
return false;
}
</script>
这篇关于HTML5表单按钮onsubmit不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文