展開和摺疊工作正常,但當列表展開時,我想將字體超棒的'+'改爲' - ',反之亦然。 DEMOJQuery用Font Awesome圖標展開摺疊
jQuery的
$('#ulCollapse li ul').hide();
$('.emplist').each(function() {
// it counts next childs of each parent
//$(this).find('.empDetails > p#leafCount span').text($(this).next('ul').children('li').length);
// it counts total childs of each parent
var childCount = $(this).siblings('ul').find('li').length;
if (childCount > 0)
$(this).find('.empDetails > p#leafCount span').append(childCount);
else
$(this).find('.empDetails > p#leafCount span').text('');
});
//expand collapse
var plusClass = 'fa-plus-circle';
var minusClass = 'fa-minus-circle';
$('.empDetails p#leafCount').css('cursor', 'pointer');
$('.empDetails p#leafCount span').on('click', function() {
var parentDiv = $(this).parents('.emplist').first();
var nextUl = parentDiv.next('ul');
nextUl.toggle();
parentDiv.closest('ul').find('ul').not(nextUl).hide();
});
謝謝你,但是一旦檢查https://jsfiddle.net/nelsonfeel/u5q9vxLc/9/ – nani0077
觀察在第三級展開最後兩個節點 – nani0077
@ nani0077,它似乎在第三級也能正常工作。我打開了第三級封閉的第二級,並再次打開第二級。顯示「+」圖標。 – Ionut