-1

我是 jQuery 环境的新手,我试图在删除一个元素后隐藏它,有一个我的 html 标记片段:

<tr <?php echo "class='m<?=$id?>' " ?> >
    <td><?=$email['first_name'] ?></td>
    <td> <?= $email["email"] ?></td>
    <td>
        <button  onclick="deleteRow(<?= $email['id'] ?>);" > Click here </button>
    </td>
</tr>

我的 jQuery 函数看起来像:

function deleteRow(id) {
    $(document).ready(function() {
        $('.m'+id).hide();
    });

    var baseurl = "<?= Zend_Registry::get('config')->app->baseUrl ?>/contactlist/contactlist";
    $.ajax({
     //some other ajax ..
     //ajax code ...
    });
}
4

2 回答 2

1

创建一个删除您的元素的页面,然后成功隐藏您的元素或用此页面中的数据替换 div... delete_your_element_here.php

  $("button[name='approve']").on('click', function() {
        var data = $(this).data();
              $.ajax({
                type:"POST",
                url: "delete_your_element_here.php",
                data: { key: data.ident, value: data.value ,id: data.deal_id}, //send your data here to be deleted here
                success: function(data){
                $('#div_to_be_replaced').html(data);//replace your div or hide the current div here
                }
         });
    });



 <button type="button" name="approve" data-ident="pdeal_deal_retail_value" style="width:90px;" data-value="<?php echo $row_rsGetDeal['deal_retail_value']; ?>"  data-deal_id="<?php echo $row_rsGetDeal['pdeal_deal_id']; ?>" class="button_blue_form">Approve</button>

像这样获取您发送的值$_POST['key'], $_POST['value'], $_POST['id']

于 2013-05-18T00:09:35.587 回答
0

如果要在成功删除后从文档中删除该行,则执行代码以删除 delete ajax 调用的成功处理程序中的元素。

 function deleteRow(id) {
    ....
    ....
    $.ajax({
       ...
       ...
       success: function(){
          $('.m'+id).remove();//You can call remove instead of hide
       }
    });
 }
于 2013-05-18T00:24:39.947 回答