dppn67180 2013-02-03 19:11
浏览 24
已采纳

从db中删除行并使用jquery进行查看

I have a webpage that shows data as followed:

| id | name   | delete |
|  1 | orange | delete |
|  2 | apple  | delete | etc...

When you press delete (its a button) you get a jquery dialog showing again two buttons. You can delete multiple items at once or only the selected item.

-------------------------------
|dialog                       |
-------------------------------
|delete this row              |
|delete entire series         |
-------------------------------

My question is: When for example 'delete this row' is selected in the dialogbox, how do I get the ID of the selected row in jquery? How can I redirect to a php page that deletes the row in the db and then redirect to the current updated page (with the row removed)?

I'm very new to jquery, but this is what I got so far:

JQuery

<script>
$(function() {
   $( ".dialog" ).dialog({ autoOpen: false });
});
$(function() {
  $(".showDialog").click( function()
       {
         $( ".dialog" ).dialog( "open");
       });   
 });
 $(function() {
  $( ".deleteEvent" ).click( function()
    { 

        $( ".dialog" ).dialog( "close");
        $(this).closest("tr").remove(); // doesn't work
    });
 });
 </script>

Dialog

<div class="dialog" title="delete event dialog">
    <input class="deleteEvent" type='button' value='delete this row'/>
</div>

Table

foreach($table as $row)
{
    echo '<tr><td>'.$row['id'].'</td>',
    '<td>'.$row['name'].'</td>',
    '<td><div class="showDialog" ><IMG style="margin-left:15px;" src="./public/pictures/trash.gif"></a></div></td>',
    '</tr>';
}
  • 写回答

1条回答 默认 最新

  • dtxzwdl08169 2013-02-03 19:13
    关注

    when you output your html with the delete input buttons, also add a hidden input field passing the id as the value

    edit:

    I misread your code, looks like you don't have individual input buttons for each displayed row. For your case, I would suggest adding the row as part of your div id value or else a custom attrib in your div, something like this:

    foreach($table as $row)
    {
        echo '<tr><td>'.$row['id'].'</td>',
        '<td>'.$row['name'].'</td>',
        '<td><div id="row_'.$row['id'].'" class="showDialog" ><IMG style="margin-left:15px;" src="./public/pictures/trash.gif"></a></div></td>',
        '</tr>';
    }
    

    or

    foreach($table as $row)
    {
        echo '<tr><td>'.$row['id'].'</td>',
        '<td>'.$row['name'].'</td>',
        '<td><div row="'.$row['id'].'" class="showDialog" ><IMG style="margin-left:15px;" src="./public/pictures/trash.gif"></a></div></td>',
        '</tr>';
    }
    

    then in your click event you can use $(this).attr('id').split('_')[1] or $(this).attr('row') respectively

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答