2015-11-14 122 views
0

我正在使用图像提交表单。但是我无法在提交之前让表单显示确认对话框。添加确认框以提交图像

我通常使用onClick()这个,但现在,因为我用它来提交它现在为我工作。

有没有办法让它工作,以便它在提交之前显示一个确认框?

<form style="margin-bottom: 0px;" method="post"> 
<input type="hidden" name="doc_to_delete" value="{$documents[sec1].doc_id}" /> 
<img src="../images/action_images/delete.jpg" style="height: 20px;" title="Delete Document" onclick="submit();"/> 
</form> 

回答

2

不要在提交按钮提交

而是使用onsubmit="return confirm('Are you sure')"

这样

<form id="form1" onsubmit="return confirm('Are you sure')" style="margin-bottom: 0px;" method="post"> 
<input type="hidden" name="doc_to_delete" value="{$documents[sec1].doc_id}" /> 
<input type="image" src="../images/action_images/delete.jpg" style="height: 20px;" title="Delete Document" /> 
</form> 
更好

不具有内联代码:

window.onload=function() { 
    document.getElementById("form1").onsubmit=function() { 
    return confirm('Are you sure'); 
    } 
} 
+0

它确实不检查th e点击时,onsubmit()。它只是立即提交。 – Marcel

+0

'任何控制台错误?你是否从图像中删除了点击处理程序?它应该顺便说一下'' – mplungjan

+0

我没有看到那部分内容。现在工作就像一个魅力:)谢谢 – Marcel