我是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 ...
});
}
答案 0 :(得分: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']
答案 1 :(得分:0)
如果要在成功删除后从文档中删除该行,请执行代码以删除delete ajax调用的成功处理程序中的元素。
function deleteRow(id) {
....
....
$.ajax({
...
...
success: function(){
$('.m'+id).remove();//You can call remove instead of hide
}
});
}