2

页面:内容显示.php

<td width="100"><a onclick="return confirmSubmit()" href="delete.php?id=<?php echo $row['id']; ?>&table=labour_details&return=content_display.php"><img src="../images/delete.png" border="0" alt="delete"></a></td>

页:删除.php

if(isset($_GET['id']) && isset($_GET['table']))
    {
        $id=$_GET['id'];
        $tablename=$_GET['table'];
        $return=$_GET['return'];




        if($tablename=="labour_details")
        {
                    $sql=mysql_query("SELECT * FROM `labour_details` WHERE `id`='$id'");
                    $row_1=mysql_fetch_array($sql);
                    $labour_name= $row_1['labour_name'];

                    if($labour_name!="")
                    {
                        $str=mysql_query("DELETE FROM `labour_details` WHERE `id`='$id'");
                        if($str)
                        {
                            header("location:$return?msg=Record Deleted Successfully!&id=$id");
                        }else{
                            echo "Problem in deleting :";
                        }
                    }

        }

}

我的问题是在哪里添加警报,以便在删除记录之前显示 javascript 消息,如果允许,它将删除记录。

function confirmSubmit()
{
    var agree=confirm("Are you sure you wish to Delete this Entry?");
    if (agree)
        return true ;
    else
        return false ;
}
4

5 回答 5

3

此行将在重定向之前显示确认对话框。

<a onclick="return confirm('Are You sure?')">...</a>
于 2013-05-10T09:59:04.883 回答
1

您可能正在寻找confirm

然后,confirmSubmit函数的主体看起来像:

function confirmSubmit() {
    return confirm ("Are you sure you want to do this?");    
}

这是因为事件处理程序在 javascript 中的工作方式。true当用户单击确定和false单击取消时,确认返回。

通过从事件处理函数返回true/false值,您可以告诉窗口是否继续处理该事件。返回false(当用户单击取消时发生)告诉浏览器停止处理事件并且不跟随链接。

于 2013-05-10T10:02:47.747 回答
1

首先你需要创建confirmSubmit() 函数

<script>
function confirmSubmit()
{
    if (confirm('Are you sure you want to delete this?'))
    {
        return true;
    }
    return false;
}
</script>

然后你把它附加到你的 A 标签上,就像你做的那样。

<a href="..." onclick="return confirmSubmit();">blah</a>
于 2013-05-10T10:01:52.757 回答
0
<a onclick="return confirm('Are you sure?')" href="delete.php">delete</a>
于 2013-05-10T10:03:21.877 回答
0
<td width="100"><a onclick="confirmSubmit(id)"><img src="../images/delete.png" border="0" alt="delete"></a></td>




function confirmSubmit(delete_id)
{
var r=confirm("Are you sure you want to delete?");

if(r==true)
{
         window.location.href = "delete.php?id="+delete_id"; ?>&table=labour_details&return=content_display.php"
    }
}
于 2013-05-10T10:02:24.483 回答