在扩展菜单时添加减号( – ),在收缩时添加(+)

我正在尝试切换当菜单扩展和收缩时+ 。 我可以选择添加和删除带有图像作为背景的类,但我决定使用+作为html。 我正在采取的方法是.remove() .append()但我被困在那里。 这是我的小提琴 。 谢谢。

试试这个

 $("#vertical-menu h3").click(function () { //slide up all the link lists $("#vertical-menu ul ul").slideUp(); $('.plus',this).html('+'); //slide down the link list below the h3 clicked - only if its closed if (!$(this).next().is(":visible")) { $(this).next().slideDown(); $('.plus').html('+'); $('.plus',this).html('-'); } }) 

Js Fiddle演示

工作样本(不要关闭所有幻灯片,为此我建议您使用Jquery UI的手风琴function)

 $("#vertical-menu h3").click(function () { //Inner var jqInner = $(this).next(); if (jqInner.is(":visible")) { jqInner.slideUp() $(this).find('span').html('-'); } else { jqInner.slideDown() $(this).find('span').html('+'); } }) 

http://jsfiddle.net/22ZyM/4/

  

如需完整菜单,请点击此处

http://blog.adlivetech.com/how-to-make-vertical-menu-with-plus-minus-toggle/