我有一個表格,它顯示不同級別的數(shù)據(jù)(父,子,孫子),當(dāng)我點(diǎn)擊它顯示與子級別相關(guān)的新行的父級時,如果我點(diǎn)擊子級,它會顯示第三級別作為具有更多行的孫子。我想要做的是在每個記錄上添加一個帶有“+”符號的按鈕,所以當(dāng)我點(diǎn)擊它時,我會看到第二個級別,并用“ - ”符號將該按鈕從父級切換到另一個,以模擬擴(kuò)展和折疊功能,我想為子級別也這樣做。現(xiàn)在,如果我點(diǎn)擊一行,列會展開或折疊,但如果我點(diǎn)擊要添加的按鈕,我想要這樣做。這是我的代碼: $('.drillDown tr td:last-child, .drillDown tr th:last-child').hide();$('.drillDown tr td:first-child, .drillDown tr th:first-child')
.dblclick(function(){
$('.drillDown tr td:last-child, .drillDown tr th:last-child').show();})
$('table.drillDown').each(function() {
var $table = $(this);
$table.find('.parent').dblclick(function() {
console.log( "*****Click on Parent" );
$(this).nextUntil('.parent', ".child").toggle("fast");
$(this).nextUntil('.parent', ".grandson").hide("fast");
});
$table.find('.child').dblclick(function() {
console.log( "*****Click on child" );
$(this).nextUntil('.child', ".grandson").toggle("fast");
});
var $childRows = $table.find('tbody tr').not('.parent').hide();
$table.find('button.hide').dblclick(function() {
$childRows.hide();
});
$table.find('button.show').dblclick(function() {
console.log("*****Click on Child");
$childRows.filter('.child').show();
});
$table.find('tr.child').dblclick(function(){
$(this).nextUntil('.child').show()
});
});而且我也完整的例子https://jsfiddle.net/ny6qcxtd/2/謝謝!
使用jQuery向按鈕添加操作
慕桂英546537
2019-04-18 14:15:49