jquery – 优化代码以提高效率问题

这对于你在Stackoverflow中的jQuery大师来说很简单.

我有以下jQuery函数,我想知道是否有一种方法来优化代码

$('.dropdown li').click(function(){
    $(this).siblings().find('.active').removeClass('active')
    $(this).siblings().find('ul:visible').slideUp();        
    $(this).toggleClass('hover');
    $('ul:first',this).slidetoggle();       
    $('.arrow-down',this).toggleClass('active');
 });

——–

快速提问:

(‘.selector“this”和(‘.selector’,这个)有什么区别?我希望我输入这个权利.

你可以看到我对jQ很新,所以即使我在问愚蠢的问题,我也需要所有的帮助^ _ ^

提前致谢.

解决方法

提示

1 – 似乎你将一个事件处理程序附加到许多< li>元素.不要那样做,而是使用delegate

2 – 不需要一直做$(this),只需要var $this = $(this);从现在开始使用$this.

3 – 如果你真的想加快速度(我没有看到BTW有任何大的性能问题),请删除jQuery并使用普通的javascript.

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...