【问题标题】:how to do confirmation in a form before submit提交前如何在表单中进行确认
【发布时间】:2014-07-04 18:51:31
【问题描述】:

我有这个代码

<form action="UMS_delete.php" method="post" onSubmit="return confirm("Are You Sure?");">
<td>
<input type="hidden" value="'.$row['username'].'" name="username">
<input type="submit" value="Delete">
</td>
</form>

我知道这很简单,但它不起作用,我不知道为什么

我也试过提交按钮上的onclick事件

但它总是转到操作页面

有人可以帮忙吗?

【问题讨论】:

  • 寻找this?
  • 在 onclick 方法中使用 type="button" 而不是 type="submit"

标签: html forms confirm


【解决方案1】:

我相信这是在确认中使用双引号。它破坏了 HTML 语法。

改为这样做: onSubmit="return Confirm('Are You Sure?');"

这应该可行,我已经做过很多次了。

【讨论】:

    【解决方案2】:

    JavaScript:

    var el = document.getElementById('myCoolForm');
    el.addEventListener('submit', function(){
    return confirm('Are you sure you want to submit this form?');
    }, false);
    

    为单独的 JavaScript 添加 ID 到表单

    <form action="UMS_delete.php" method="post" id="myCoolForm" onSubmit="return confirm("Are You Sure?");">
    <td>
    <input type="hidden" value="'.$row['username'].'" name="username">
    <input type="submit" value="Delete">
    </td>
    </form>
    

    或者你总是可以像这样使用内联 JS 代码:

    <form action="adminprocess.php" method="POST" onsubmit="return confirm('Are you sure you want to submit this form?');">
    <input type="submit" name="completeYes" value="Complete Transaction" />
    

    【讨论】:

    • @David Pullar,类型很好。我有表格可以做到这一点并且工作得很好!
    【解决方案3】:

    你刚刚通过 onclick 函数放了

    > <input type="submit" name="completeYes" value="Complete Transaction" onclick="return confirm("Are You Sure?");"/>
    

     onclick="return confirm('Are You Sure?');"
    

    【讨论】:

      猜你喜欢
      • 2011-09-23
      • 1970-01-01
      • 2014-09-22
      • 1970-01-01
      • 1970-01-01
      • 2015-03-11
      • 2013-04-28
      • 2015-03-08
      • 2011-09-21
      相关资源
      最近更新 更多