使用jquery展开表中的偶数tr标记
我有一个表格格式的数据,如下面的屏幕截图 我需要在点击使用jquery展开表中的偶数tr标记,jquery,html-table,Jquery,Html Table,我有一个表格格式的数据,如下面的屏幕截图 我需要在点击ExpandAll按钮时显示所有tr标签,这些标签具有ChildBundle类 下面是我用来执行操作的jQuery代码 $(document).on('click', '#ExpandAll', function () { $('#view_job_tbl > tbody > tr').each(function () { var className = $(this).attr('class');
ExpandAll
按钮时显示所有tr
标签,这些标签具有ChildBundle
类
下面是我用来执行操作的jQuery代码
$(document).on('click', '#ExpandAll', function () {
$('#view_job_tbl > tbody > tr').each(function () {
var className = $(this).attr('class');
var number = parseFloat(className.match(/-*[0-9]+/));
if ($('.ChildBundle' + number + ':visible').length)
$('.ChildBundle' + number).hide();
else
$('.ChildBundle' + number).show();
});
});
但这是行不通的。有人能帮我吗?你可以试试这个:
$('#view_job_tbl > tbody > tr[class*=ChildBundle]').each(function () {
$(this).toggle();
});
我认为扩展tr是不可能的,您必须扩展TDR。没有其他方法可以做到这一点:(@WaldemarIce不是真的。请去掉类名中的数字。类应为常用的通用名称。使用ID创建唯一标识符或在数据中存储数据attributes@charlietfl:您的意思是我是否需要创建没有编号的
类名
?引用不匹配的语法问题是的,对不起,我已删除了“.FYI-也是d”在上不需要每个
。可以在整个集合上使用toggle()
。是的,我知道,但是有了。对于Pankaj,每个都更容易理解。