Pet*_*ter 1 datatable jquery jquery-plugins
我正在使用此代码初始化数据表,并且在单击了“删除”链接后-一切正常,但是我正在使用刷新页面,因此我尝试使用DataTable函数直接删除行,但是根本无法使它工作。这是当前代码(有效,但刷新整个页面的代码):
<script type="text/javascript">
$(document).ready(function() {
$('#publishers').dataTable( {
"iDisplayLength": 50,
"sPaginationType": "full_numbers",
"bStateSave": true
} );
} );
function DeletePublisher(publisherid) {
jConfirm('Are you sure you want to delete this publisher?', 'Delete publisher', function(r) { if (r)
$.ajax({
type: "GET",
url: 'includes/publishers/delete-publisher.php?publisherid=' + publisherid,
data: '',
success: function(response){
$.jGrowl('Publisher deleted');
window.location.reload();
}
});
});
}
</script>
Run Code Online (Sandbox Code Playgroud)
在身体上
...A LOT OF UNINTERESTING COLUMNS, AND THE ONE WITH ACTION:
<td class="action-th">
<ul class="button-table-head">
<li><div class="button-head edit-icon"><a href="#" class="sweet-tooltip" data-text-tooltip="Edit" data-style-tooltip="tooltip-mini-slick"><span>Edit</span></a></div></li>
<li><div class="button-head delete-icon"><a href="#" class="sweet-tooltip" data-text-tooltip="Delete" data-style-tooltip="tooltip-mini-slick" onclick="DeletePublisher('<?php echo $publisher_id; ?>')"><span>Delete</span></a></div></li>
</ul>
</td>
Run Code Online (Sandbox Code Playgroud)
我尝试使用此代码,但是没有用:
function DeletePublisher(publisherid) {
jConfirm('Are you sure you want to delete this publisher?', 'Delete publisher',function(r) { if (r)
$('#publishers tbody').on( 'click', 'tr', function () {
var tr = this;
$.ajax({
type: "POST", //or GET
url: 'includes/publishers/delete-publisher.php?publisherid=' + publisherid,
data: '',
success: function(response){
t.fnDeleteRow( tr );
$.jGrowl('Publisher deleted');
}
} );
});
});
}
Run Code Online (Sandbox Code Playgroud)
任何想法为什么-我完全不喜欢JS,JQuery ...
如果您传递对clicked元素的引用,则可以轻松做到这一点:
onclick="DeletePublisher(this,'<?php echo $publisher_id; ?>')"
Run Code Online (Sandbox Code Playgroud)
然后在您的函数中:
function DeletePublisher(element,publisherid) {
...
success: function(response){
$(element).parents('tr').remove()
$.jGrowl('Publisher deleted');
}
...
}
Run Code Online (Sandbox Code Playgroud)
......那就不叫 window.location.reload();在所有
| 归档时间: |
|
| 查看次数: |
4197 次 |
| 最近记录: |