Php 使用Javascript和jQuery确认删除

Php 使用Javascript和jQuery确认删除,php,jquery,mysql,Php,Jquery,Mysql,//函数从数据库中获取所有类别 function find_all_category(){ global $connection; $query = "SELECT * FROM `category`"; //getting data from db $get_cat_details = mysqli_query($connection, $query); while($row=mysqli_fetch_assoc($get_cat_deta

//函数从数据库中获取所有类别

function find_all_category(){

    global $connection;

    $query = "SELECT * FROM `category`"; //getting data from db 
        $get_cat_details = mysqli_query($connection, $query);
        while($row=mysqli_fetch_assoc($get_cat_details)) { // fetch-array
        $cat_id=$row['catid'];
        $cat_name=$row['catname'];
        echo "<tr>";
        echo "<td>{$cat_id}</td>";
        echo "<td>{$cat_name}</td>";
        echo "<td><a href='category.php?edit={$cat_id}'><i class='fa fa-pencil- 
               square-o' aria-hidden='true' style='color:purple;'></i></a> 
               </td>";      
        echo "<td><a class='item_delete' href='category.php?delete={$cat_id}'><i 
              class='fa fa-trash-o' aria-hidden='true' style='color:red;'></i> 
              </a></td>"; // contains class to be used in javascript
        echo "</tr>";
    }
}

不工作,请帮助

使用下面的代码时出现语法错误。您错过了函数的开头

$(".item_delete").click(function() {
    return confirm("Are you sure you want to delete ?");
});

在这样的变量中应该有confirm的值

$('body').on('click', '.item_delete', function() {

   return confirm("Are you sure you want to delete ?"); // if you just want 
   // to return the confirm

   // or you can delete based on conditions as
   var statusDelete = confirm("Are you sure you want to delete ?");


  if(statusDelete  == "true"){
// call function to delete
   }
 if(statusDelete  == "false"){
// call function when cancel clicked
   }

};

委派事件的优点是,它们可以处理来自子元素的事件,这些子元素将在以后添加到文档中。我们可以使用委派事件将单击事件绑定到动态创建的元素。
$(文档)。on('click','.item_delete',function(){return confirm(“您确定要删除吗?”);});
谢谢您的回复,但仍然没有响应,它只是删除了类别。语法错误在哪里?这看起来与OPs代码完全相同。OP没有起始
{
函数。代码没有给出任何错误,它对表行没有任何影响OP使用返回值将其返回到click事件。它似乎是事件委派的问题。此代码应该可以正常工作。
$('body').on('click', '.item_delete', function() {

   return confirm("Are you sure you want to delete ?"); // if you just want 
   // to return the confirm

   // or you can delete based on conditions as
   var statusDelete = confirm("Are you sure you want to delete ?");


  if(statusDelete  == "true"){
// call function to delete
   }
 if(statusDelete  == "false"){
// call function when cancel clicked
   }

};