AJAX 调用传递 <div> 而不是 <button>

AJAX call passes the <div> instead of the <button> one

我想知道为什么这个 ajax 调用传递 div id 而不是我想要的按钮 id。

            <?php
           while($info = mysqli_fetch_array($sql))
           {

            echo "<tr>

             <th>" .$info['name']. "</th>
             <th>" .$info['pass']. "</th>
             <th><a href=\"http://" .$info['link']. "\">" .$info['link']. "</a></th>
              <th><div class=\"delbuttons\" id='5'> <button  data-toggle=\"modal\" data-target=\"#myModal\"  id='" .$info['id'].  "'> Delete </button> </div> </th> </tr> ";

           }
           ?>
     </table>
     <script>
        $(document).ready(function(){
            $('.delbuttons').click(function() {
                $.ajax({
                type: 'get',
                url: 'ajax.php',
                data: { 
                    row: this.id
                },
                success: function(msg){
                    if (msg)
                        alert(msg);

                    location.reload();
                }
                });
            });
        });
     </script>

我将按钮 ID 设置为 5 只是为了调试,正如我预期的那样,它返回了“5”而不是按钮的 ID。

我都试过了,得到 & post。

提前致谢!

你 select 正在 $('.delbuttons'),所以 this 指的是 <div>

要么 select $('.delbuttons button') 代替,要么使用 $(this).children(":first").attr("id") or some other way to get the first element child in jQuery 代替 this.id.