本文介绍了如何在JQuery数据表的每一行中添加多个按钮,以及如何在其上应用事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个按钮,但是我需要两个按钮并在单击它们以从底层数据库获取数据时执行一些MySql.
I have one button but I need two buttons and perform some MySql when they are clicked to get data from the underlying database.
如何使用这两个按钮执行事件?
How can I perform an event using these two buttons?
$(document).ready(function () {
var table= $('#example').dataTable( {
"ajax": "..//wp-content/plugins/jobify/Admin/data.txt",
"columnDefs": [ {
"targets": -1,
"data": null,
"defaultContent": "<button>View Posted Jobs</button>"
} ]
} );
$('#example tbody').on( 'click', 'button', function () {
//var data = table.row( $(this).parents('tr') ).data();
} );
} );
推荐答案
只需为每个按钮分配一个类,并将事件处理程序附加到每个类.
Just assign a class to each button and attach an event handler to each class.
$(document).ready(function () {
var table = $('#example').dataTable( {
"ajax": "../wp-content/plugins/jobify/Admin/data.txt",
"columnDefs": [ {
"targets": -1,
"data": null,
"defaultContent":
'<button class="btn-view" type="button">View Posted Jobs</button>'
+ '<button class="btn-delete" type="button">Delete</button>'
} ]
} );
// Handle click on "View" button
$('#example tbody').on('click', '.btn-view', function (e) {
//var data = table.row( $(this).parents('tr') ).data();
} );
// Handle click on "Delete" button
$('#example tbody').on('click', '.btn-delete', function (e) {
//var data = table.row( $(this).parents('tr') ).data();
} );
});
这篇关于如何在JQuery数据表的每一行中添加多个按钮,以及如何在其上应用事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!