jquery - 为什么我的 jquery td click 事件在 Chrome 上 react 慢?

标签 jquery css google-chrome optimization

我有一个大表(大约 500 行和 7 列)。 我的代码只需要检查我单击的表格单元格(它将“保留”类添加到单击的单元格,此类执行一些简单的边框操作)。

它在 Firefox 和 Opera 上运行顺畅,但在 Chrome 上却很糟糕(我的意思是我必须等待大约一秒钟才能更改单元格的边框)- 你能建议我一种修复它的方法吗?

第一个 IF 用于一些其他检查,但它只是检查这个特定点击单元格的状态。

$("td").click( function() 
{
    if($(this).attr('system') !=  1)
    {
        if($(this).attr("reserved") != "1" && $(this).attr("reserved") != "2")
        {
            if($(this).attr("_checked")=="1")
            {
                $(this).addClass("reserved"); // here it changes border color
            }

        }
}

最佳答案

您可以尝试缓存选择器:

$("td").click( function() 
{
    var $this = $(this);

    if($this.attr('system') !=  1)
    {
        if($this.attr("reserved") != "1" && $this.attr("reserved") != "2")
        {
            if($this.attr("_checked")=="1")
            {
                $this.addClass("reserved"); // here it changes border color
            }

        }
}

关于jquery - 为什么我的 jquery td click 事件在 Chrome 上 react 慢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14440392/

相关文章:

javascript - 如何加载内容(包括内容的图像)然后淡入淡出?

javascript - 如何将输入字段扩展到 div 末尾

jQuery UI 选项卡 - 删除选项卡后面的标题和内容区域

jquery - 将鼠标悬停在表格行上在单元格之间移动时触发

javascript 生成器功能不起作用

javascript - Rails6 禁用所有非 ActiveAdmin 页面的 ActiveAdmin 布局

javascript - 如何使用CSS更改浏览器管理密码窗口的位置

debugging - Chrome 中出现 "Aw Snap"屏幕时如何获取更多信息?

php - "Chrome detected unusual code"之前工作的 iframe 错误

javascript - jQuery MouseEnter/Leave with fadeIn() 闪烁