继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

点击表格获取表格行或列索引

慕粉0415482673
关注TA
已关注
手记 297
粉丝 64
获赞 367

参考ASP.NET MVC的视图:

 

此段html将产生一个表格table。

现在我们需要实现,点击表格时,获取点击行的索引或是所在行的列索引。

行索引:

 

 $('table tr').click(function () {            var idx = $(this).index();            alert(idx);        });

Source Code



列索引:

 

$("table tr td").on("click", function () {            var idx = $(this).index();            alert(idx);        });

Source Code



演示:

 

以下内容于2017-03-07 16:13分添加:
还可以使用下面jQuery代码,进行获取,仅多一些参考而已:

 

 $('table tr').on("click", 'td', function () {            var tdidx = $(this).index();            var tridx = $(this).closest('tr').index();        });              $("table tr td").on("click", function () {            var tdidx = $(this).index();            var tridx = $(this).closest('tr').index();             });

Source Code

 

打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP