php代码之前的javascript警报

时间:2013-05-10 09:55:34

标签: php javascript

page:content display.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>

页:delete.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 ;
}

5 个答案:

答案 0 :(得分:3)

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

<a onclick="return confirm('Are You sure?')">...</a>

答案 1 :(得分: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>

答案 2 :(得分:1)

您可能正在寻找confirm

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

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

这可以归功于事件处理程序在javascript中的工作方式。当用户单击“确定”时确认返回true,单击“取消”时返回false

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

答案 3 :(得分: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"
    }
}

答案 4 :(得分:0)

<a onclick="return confirm('Are you sure?')" href="delete.php">delete</a>