1

在这里,我不想从提交按钮传递参数。任何人都可以帮助我相应地提示确认消息

return confirm("Are you sure to Approve/Reject/Delete ?");

我的html代码

<form name="pendingrequest" id="pendingrequest" action="formhandler.php" method="POST" onsubmit="return confirmation(this);">
            <table >
                <tr>
                    <td><input type="submit" name="action" value="Approve"></td>
                    <td><input type="submit" name="action" value="Reject"></td>
                    <td><input type="submit" name="action" value="Delete"></td>
                </tr>
            </table> 
</form>

例如,如果有人点击批准,我想要这个:

return confirm("Are you sure to Approve?");
4

1 回答 1

1

如果您使用,则没有跨浏览器解决方案onsubmit

这样做的唯一方法是将事件绑定到按钮而不是提交表单:

<!DOCTYPE html>
<html>
 <head>
  <script>
   function init()
   {
    document.getElementById("pendingrequest").onsubmit = function(e)
    {
     console.log(e.target.value);
     console.info(e.srcElement);
     return false;
    }

    var submits = document.getElementsByClassName("submit-test");
    for(var i=0;i<submits.length;i++)
    {
     submits[i].onclick = function(e){
      var value = this.value;
      return confirm("Are you sure to "+value+" ?");
     }
    }
   }
  </script>
 </head>
 <body onload="init()">

  <form name="pendingrequest" id="pendingrequest" action="" method="POST" >
   <table >
    <tr>
     <td><input class="submit-test" type="submit" name="action" value="Reject"></td>
     <td><input class="submit-test" type="submit" name="action" value="Approve"></td>
     <td><input class="submit-test" type="submit" name="action" value="Delete"></td>
    </tr>
   </table> 
  </form>
 </body>
</html>
于 2013-11-01T10:44:36.400 回答