PHP javascript确认删除框


php javascript confirm box for delete

以下代码为PHP

echo "<input type='submit' name='delete' value='$t2[0]' class='delete_button' onclick='return confirm('Please Confirm Delete');'>"

我试图创建一个删除按钮,当用户单击删除按钮时,它应该询问确认。但在这种情况下,它不起作用。

是否有最好的方法删除与确认在PHP//或javascript没有ajax

你的引号断了;

onclick='return confirm('Please Confirm Delete');'>

而不是使用;

onclick="return confirm('Please Confirm Delete');">

在javascript中,你可以这样做:

<>之前//javascript函数函数askme() {if(confirm("Are you sure you want to delete this.. ")) {//删除这句}}

引号是错误的,用这个代替:

 echo "<input type='submit' name='delete' value='$t2[0]' class='delete_button' onclick='return confirm('"Please Confirm Delete'");'>"

通过在confirm中再次打开单引号,您将超出您的属性。

你不能"在jquery中调用php代码"。你唯一能做的就是向服务器端PHP脚本设置一个请求(AJAX),该脚本将接管你转移到脚本中的相应参数,并产生一个输出(使用echo或print),该输出将在请求的回调中自动可用。

使用jQuery就这么简单

$.post('url/to/script.php', {parameter1: 'whatever', param2: 'something'}, function(response) {
   // the output of the PHP script is available in the variable "response"
   alert(response);
});

PHP脚本可以接管参数,对其进行任何操作并创建输出

$param1 = $_POST["parameter1"];
$param2 = $_POST["param2"];
// do whatever you want with $param1 and $param2
// create some output using echo/print
echo "This will be transferred back to the calling Javascript";

你可以试试这个,很简单,而且很有效。

   <td> <a  onClick="return confirm('DELETE: Are You sure ??');"  href="member_delete?id=<?php echo $row['memID'];?>" >delete <i class="fa fa-trash-o" aria-hidden="true"></i></a></td> [DEMO][1]

我假设它在成员的表列表中。