0

如何在从数据库中删除条目之前添加问题警报窗口(类似于“删除第 2 行?”)?

<script type="text/javascript">
function deleteRow(tableName,colName,id, obj){
    $.ajax({
           type: "POST",
           url: "callpage.php?page=tables/delete.php",
           data: "tableName=" + tableName + "&colName=" + colName + "&id=" + id,
           success: function(msg){
             if(msg === '1'){
                obj = $(obj).parents('tr');
                $(obj).slideUp().remove();
             }
             else
                 alert("Error.");
           }
    });
}
</script>
4

6 回答 6

2

您可以使用 JavaScript 的window.confirm()函数向用户显示确认对话框,并if根据他们的选择显示一个简单的语句,即OK( true) 或Cancel( false):

<script type="text/javascript">
function deleteRow(tableName,colName,id, obj){
    if(window.confirm('Delete row ' + id + '?')){
        $.ajax({
               type: "POST",
               url: "callpage.php?page=tables/delete.php",
               data: "tableName=" + tableName + "&colName=" + colName + "&id=" + id,
               success: function(msg){
                 if(msg === '1'){
                    obj = $(obj).parents('tr');
                    $(obj).slideUp().remove();
                 }
                 else
                     alert("Error.");
               }
        });
    }
}
</script>
于 2012-05-25T08:18:39.653 回答
0

您需要使用 javascript确认框,该 puprose 将完成您的任务

function deleteRow(tableName,colName,id, obj){ 
    var r=confirm("you need to delete row from" + tableName + "having id :" +id );
    if (r==true)
      {
           $.ajax({
                   type: "POST",
                   url: "callpage.php?page=tables/delete.php",
                   data: "tableName=" + tableName + "&colName=" + colName + "&id=" + id,
                   success: function(msg){
                     if(msg === '1'){
                        obj = $(obj).parents('tr');
                        $(obj).slideUp().remove();
                     }
                     else
                         alert("Error.");
                   }
            });

       }
    else
      {
      alert("You pressed Cancel!");
      }
}
于 2012-05-25T08:17:53.460 回答
0

您可以使用带有类似代码的确认窗口

if (confirm('Want to delete row XY ? ')) {
    $.ajax({
           type: "POST",
           url: "callpage.php?page=tables/delete.php",
           data: "tableName=" + tableName + "&colName=" + colName + "&id=" + id,
           success: function(msg){
             if(msg === '1'){
                obj = $(obj).parents('tr');
                $(obj).slideUp().remove();
             }
             else
                 alert("Error.");
           }
    });
}
于 2012-05-25T08:18:17.283 回答
0

您应该在通话前添加一个确认弹出窗口:

function deleteRow(tableName, colName, id, obj) {
  if(confirm("Are you sure to delete this row?")) {
    // ...
  }
}
于 2012-05-25T08:18:30.620 回答
0

在 ajax 调用之前放置一个 html confirm()。

就像是

var r=confirm("Do you want to delete?")
if (r==true)
{
  //call the delete function
}
于 2012-05-25T08:18:40.947 回答
0

确认框的简单和非常基本的解释。

var r=confirm("按下一个按钮");
如果(r==真)
{
  alert("你按下了确定!");
}
别的
{
  alert("你按下了取消!");
}

于 2012-05-25T08:19:19.417 回答