如果单击“删除”链接,则向用户显示一个“ JavaScript确认”弹出框。

时间:2019-02-22 08:26:38

标签: php mysql

我应该在脚本中写些什么来删除行

<script type="text/javascript">

function confirmation()
{
    var del=confirm("Are you sure you want to delete this record?");
    if (del==true){
   alert ("record deleted")
}
    return del;
}

</script>

体内

<td><a href="movie_list(delete).php?view&movid" onclick="return confirmation();">Delete</a></td>

这部分我应该怎么做?

<?php

    if (isset(.....) 
    {
        ....
        header("Location: .....php");
    }

    ?>

2 个答案:

答案 0 :(得分:1)

将此添加到您的删除按钮

onclick="return confirmDelete();"

将此内容粘贴到页面的页眉或页脚。

<script>function confirmDelete() {
            if (confirm("Sure you want to delete ?") == true) {
                return true;
            } else {
                return false;
            }
        }
    </script>

答案 1 :(得分:0)

<td><button onclick="return confirmation();">Delete</button></td>
    <input type="hidden" name="movid" value="<?php echo 10; ?>">

<script type="text/javascript">

var movid = $('#movid').val();

function confirmation()
{
    if (confirm("Are you sure you want to delete this record?"))
    {
        alert ("record deleted");
        window.location.href='movie_list(delete).php?movid='+movid;
    }

}
</script>

//在movie_list(delete).php上

<?php

if (isset($_GET['movid'])) {
    header("Location:index.php");
}


?>