$.post值不正确.JQuery中的选择


Incorrect value of $.post. Selection in JQuery

我有一个文件delete.php包含

<?php
$folder = "./fak/";
$filename = $_POST['name'];
unlink($folder.$filename);   
?>

和index.html文件

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script>
  $(document).ready(function(){
    $(".delete").click(function(){
      $.post("delete.php",
      {
        name:$(".delete").attr("value")
      },
      function(data, status){
        alert("data:"+ data + "'n Status:" + status)
        location.reload();
      });
    });
  });
</script>
</head>
<body>
  <div class="item">
    <img src="./fak/1.png">
    <button class="delete" value="1.png"> delete img </buttom>
  </div>
  <div class="item">
    <img src="./fak/2.png">
    <button class="delete" value="2.png"> delete img </buttom>
  </div>
</body>
</html>

这里是我的问题,无论我插入哪个按钮delete.php删除1.png。当我再次插入按钮时,jQuery警告文件1.png不存在。

所以我的问题是在选择正确的值和执行php文件后清除值'name'

$(".delete").attr()将始终返回第一个,替换为

   $(".delete").click(function(){
      $.post("delete.php",
      {
        name:$(this).attr("value")
      },
      function(data, status){
        alert("data:"+ data + "'n Status:" + status)
        location.reload();
      });