jQuery Datatables-如何在单击该行中的按钮时获取该行的索引 [英] jQuery Datatables - How to get the index of a row when a button in that row is clicked

查看:126
本文介绍了jQuery Datatables-如何在单击该行中的按钮时获取该行的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这就是我想要做的:

我在每一行中都有一个编辑按钮.当用户单击该编辑按钮时,我需要获取该行的索引.有人知道怎么做吗?请查看下面的我的数据表"实时链接,以进一步了解我的问题并进行必要的更改.

I have an edit button within every row. when the user clicks on that edit button, I need to get the index of that row..but I'm not sure how exactly to do that. Anyone know how to do this? Please check out my Datatables live link below to further understand my problem and make any necessary changes.

Datatables实时链接: http://live.datatables.net/madadak/2/edit

Datatables live link: http://live.datatables.net/madadak/2/edit

谢谢!

推荐答案

将jQuery代码更改为:

Change the jQuery code to be this:

$(document).ready( function () {
var table = $('#example').DataTable();
    $("#example tbody").on('click', '.editButton', function() {
        alert('Row index:' + $(this).closest('tr').prevAll().length );
    });                      
} );

它从索引0开始,我希望这是您想要的.如果您想知道,我在这里找到它.

It starts with index 0 which I hope is what you want. I found it here if you're wondering.

这篇关于jQuery Datatables-如何在单击该行中的按钮时获取该行的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆