单击链接时删除确认

时间:2013-09-04 10:25:32

标签: php javascript html

我在while循环中有这个代码,用于从数据库中获取数据。我想在点击Delete链接时显示确认弹出窗口。

echo "<td><a href='delete.php?id=" . $row['serial_no'] . "'>Delete</a></td>";

如何做到这一点?

5 个答案:

答案 0 :(得分:1)

从JavaScript尝试confirm函数,尽可能快地学习jQuery并尝试从html中分离javascript;)。

http://www.w3schools.com/jsref/met_win_confirm.asp

<td>
    <a href="delete.php?id=<?php echo $row['serial_no'] ?>" id="a_id">
        Delete
    </a>
</td>

<script type="text/javascript">
    $(function() {
        $('td a#a_id').click(function() {
            return confirm("Are You sure that You want to delete this?");
        });
    });
</script>

答案 1 :(得分:1)

为锚链接添加onClick属性并在其上调用该函数。或者只是显示confirm

<a onClick = "confirm ('Are You Sure?')"

完成示例

function disp_confirm()
{
    var r=confirm("Press a button!")
    if (r==true)
    {
        alert("You pressed OK!")
    }
    else
    {
        alert("You pressed Cancel!")
    }
}

<a onclick="disp_confirm()" 

答案 2 :(得分:0)

试试这个

function DeleteClick(serial_no)
{
if(confirm('Are you sure to delete ' + serial_no + '?'))
{
    alert('Data deleted');
    return true;
}
return false;
}

echo "<td><a href='delete.php?id=" . $row['serial_no'] . "' onclick="return 
 DeleteClick(\''. $row['serial_no'].'\')">Delete</a></td>";

答案 3 :(得分:0)

echo "<td><a href='delete.php?id=" . $row['serial_no'] . "' onclick=\"return confirm('Are you sure you want to delete?');\">Delete</a></td>";

答案 4 :(得分:0)

试试这段代码,希望它能起作用 -

<td>
    <a href="#" onclick="conf("delete.php?id=".<?php echo $row['serial_no']; ?>.")">
        Delete
    </a>
</td>

<script type="text/javascript">
    function conf(str) {
       if(confirm("Your Message") == true){ location.replace(str);}
    }
</script>

并在delete.php页面中 - 只需从url中获取id并运行删除查询。