JavaScript处理onClick返回值

时间:2014-04-28 20:15:35

标签: javascript html validation

我有以下代码来删除文档

<tr> To replace the document, you will need to first delete the current one. 
  <form name="delete_attachment_form" action="apr_attachment.cfc?method=delete_apr_attachment" method="post">
    <input type="hidden" name="apr_attachment_id" value="#apr_attachment_id#">
    <input type="hidden" name="apr_section_id" value="#apr_section_id#">
    <input type="hidden" name="submit_mode" value="DELETE">
    <input type="submit" onClick ="confirm('Are you sure you want to delete the current project activities document')" Value="Delete"> 
  </form> 

但这是删除文件而不管用户点击确定/取消,我希望只删除文件,我该怎么办?

2 个答案:

答案 0 :(得分:1)

试试这个:

HTML:

<input type="submit" onClick ="return checkForm()" Value="Delete">

JS:

function checkForm() {
    if (confirm("Are you sure")) {
        alert("Clicked Ok");
        return true;
    } else {
        alert("Clicked Cancel");
        return false;
    }
}

答案 1 :(得分:1)

以下是对提交按钮的单行编辑:

<input type="submit" onClick ="if(!confirm('Are you sure you want to delete the current project activities document')) return false;" Value="Delete">