我试图让我的脚本在按下“定位按钮”后完全删除该行。我有以下代码,但我似乎无法让它正常工作。是的,DataTables 中的表名被命名为“dataTables-example”。
按钮:
<td><button type="button" name="locateButton1" class="btn btn-info" onClick="UpdateLocate(<?php echo $orow['wo']; ?>);"/>Locates</button></a></td>
Run Code Online (Sandbox Code Playgroud)
脚本:
<script>
function UpdateLocate(wo)
{
jQuery.ajax({
type: "POST",
url: "functions/markLocates.php",
data: 'wo='+wo,
cache: false,
success: function(response)
{
//alert("Record successfully updated");
$('#dataTables-example').on( 'click', 'a.editor_remove', function (e) {
e.preventDefault();
editor
.title( 'Edit record' )
.message( "Are you sure you wish to delete this row?" )
.buttons( { "button": "locateButton1", "fn": function () { editor.submit() } } )
.remove( $(this).closest('tr') );
} );
}
});
}
Run Code Online (Sandbox Code Playgroud)
我能够通过以下方式完成此操作
$("#dataTables-example").on('click', '.btn-info', function () {
$(this).parent().parent().remove();
});
Run Code Online (Sandbox Code Playgroud)
试试这个。这是工作示例
<table id="example" class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Position</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Tiger Nixon</td>
<td>System Architect</td>
<td><button>Delete</button></td>
</tr>
</tbody>
</table>
<script>
$(document).ready(function () {
var table = $('#example').DataTable({
"columns": [
null,
null,
null,
{
"sortable": false
}
]
});
});
$('#example').on("click", "button", function(){
console.log($(this).parent());
table.row($(this).parents('tr')).remove().draw(false);
});
</script>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11191 次 |
| 最近记录: |