-3

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

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

如何才能做到这一点?

4

5 回答 5

1

尝试confirmJavaScript 中的函数,尽可能快地学习 jQuery,并尝试将 javascript 与 html 分开;)。

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>
于 2013-09-04T10:26:48.247 回答
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()" 
于 2013-09-04T10:27:42.583 回答
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>";
于 2013-09-04T10:28:57.747 回答
0
echo "<td><a href='delete.php?id=" . $row['serial_no'] . "' onclick=\"return confirm('Are you sure you want to delete?');\">Delete</a></td>";
于 2013-09-04T10:29:04.323 回答
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 并运行删除查询。

于 2013-09-04T10:39:46.283 回答