这几天在负责帮助中心改版的项目,其中左栏(浏览下面的测试页面)有一个显示隐藏导航的功能,这个跟scrollTab不同了,它只涉及到一个ul显示隐藏,并且还是li的childNodes,所以可以给li添加事件,来触发ul的显示隐藏。 由于公司内使用YUI作为开发的基础库,所以开始的时候也就从YUI的delegate事件来实现功能了:《效果页面》,并且下面的代码有一个优化效果:记录前面点击过的元素,在点击下一个tab的时候隐藏之前点击过的tab。 [javascript] <script src="http://k.kbcdn.com/global/utilities/utilities_1_4_24.js"></script> <script> (function(){ var _E=YK.E,_D=YK.D,tempEl=null; YK.load(["event-delegate"],function(){ if(_D.inDocument("question-catagroy")){ _E.delegate("question-catagroy","click",function(e,matchEl,root){ if(matchEl.className === "catagroy-title"){ var temp=null; temp=matchEl.parentNode; if(!tempEl){ tempEl=_D.getFirstChild(root); … 了解更多