展开和折叠工作正常,但当列表展开时,我想将字体超棒的'+'改为' - ',反之亦然。 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