0

我在同一个表单上有两个提交按钮用于编辑和删除,我想发出删除确认警报。我已经尝试过,但这只能工作,但是我在删除确认中选择“否/取消”。我应该怎么办 ?

这是表格

<form name="form" method="POST" action="update.php">
//form code
<input name="update_button" type="submit" value="Update" />
<input type="submit" name="delete_button" onClick="javascript:confirmDelete();" value="Delete"/>

这是javascript

<script type="text/javascript">
function confirmDelete()
{
    var status = confirm("Are you sure you want to delete ?");
    if(status)
    {
        parent.location.replace("parent.location='<?php echo "update.php";?>'");
    }else
    {
        parent.location.replace("parent.location='<?php echo "form.php?ticket=".$c['no'] ?>'");
    }
}
</script>

这是update.php

if(isset($_POST['update_button']))
{
    //update proses
}
else if(isset($_POST['delete_button']))
{
    //delete proses
}

我要删除确认显示“您确定要删除吗?” 如果我选择“是”,它将从数据库中删除,如果我选择“取消”,它将停留在当前页面(form.php)。

之前谢谢

4

2 回答 2

1

您不需要添加或任何javascript:事件onclick处理属性。只需使用onclick="return confirmDelete();"

你的javascript会是这样的:

<script type="text/javascript">
  function confirmDelete() {
    var status  = confirm( "Are you sure you want to delete ?" );
    return status;
  }
</script>

或者你可以使用onclick="return confirm( 'Are you sure you want to delete ?' );"

于 2013-06-26T03:53:53.877 回答
0

html:

<form name="form" method="POST" action="">
<input name="update_button" type="submit" value="Update" />
<input type="button" name="delete_button" id="delete_button" value="Delete"/>

Javascript:

$("#delete_button").on('click',function(){
  if(confirmDelete()){
    parent.location.replace("parent.location='<?php echo "update.php";?>'");
  }
  else{
      parent.location.replace("parent.location='<?php echo "form.php?ticket=".$c['no'] ?>'");
   }
});

function confirmDelete(){
  var status = confirm("Are you sure you want to delete ?");
    if(status)
    {
        return true;
    }
  return false;
}
于 2013-06-26T04:28:46.430 回答