删除确认对话框仅适用于 table 中的第一行

delete confirm dialog is only worked for the first row in a table

这是我的示例 table,我在那里有 2 个图标用于编辑操作和删除。 删除时,我想弹出一个确认对话框。仅当我单击第一行的删除图标时它才有效。
对于其他行,缺少 jQuery 事件(不工作)。

这是我的 .php 编码文件。

<tbody>    
//data connection with db
while ($row = mysql_fetch_array ($res))
{
    //data rows
?>
<tr class="odd" role="row" id="row_5"> 
    <td align="center">
        <a href="#"><img src="../images/sys_icon_edit.png" width="20" height="20" alt="Edit"></a> 
        <a id="id-btn-dialog2" href="#"><img src="../images/icon_trash.png" width="20" height="20" alt="Delete"></a>
    </td>   
    //other data fields here
</tr>    
<?php
}
?>     
</tbody>

这是与之相关的jquery

jQuery(function($) {

                $( "#id-btn-dialog2" ).on('click', function(e) {e.preventDefault();
                $( "#dialog-confirm" ).removeClass('hide').dialog({
                        resizable: false,
                        width: '320',
                        modal: true,
                        title_html: true,
                        buttons: [{
                                html: " Delete ",
                                "class" : "btn btn-danger btn-minier",
                                click: function() {
                                    $( this ).dialog( "close" );
                                }},
                                {
                                html: " Cancel ",
                                "class" : "btn btn-minier",
                                click: function() {
                                    $( this ).dialog( "close" );
                                }
                            }]
                    });
                });
})  

请帮帮我,我该怎么做?对于 php、jQuery 和 javascript,我都处于初学者水平。
那个jQuery代码是我在网上找的,我只是改了标题文字,没有改功能代码。

提前致谢。

您正在为一个元素的多个实例使用 ID / #

请尝试使用 class。

有关更多信息和研究,请访问 this link

这是Example我将如何做的。

为您的删除按钮使用 class 而不是 id,并将处理程序设置为您的 body 标记以支持动态添加的行。

$( "body" ).on('click', ".delete", function(e) {
            e.preventDefault();
            $( "#dialog-confirm" ).removeClass('hide').dialog({
                    resizable: false,
                    width: '320',
                    modal: true,
                    title_html: true,
                    buttons: [{
                            html: " Delete ",
                            "class" : "btn btn-danger btn-minier",
                            click: function() {
                                $( this ).dialog( "close" );
                            }},
                            {
                            html: " Cancel ",
                            "class" : "btn btn-minier",
                            click: function() {
                                $( this ).dialog( "close" );
                            }
                        }]
                });
            });