【问题标题】:Comma-separated jQuery selectors performance逗号分隔的 jQuery 选择器性能
【发布时间】:2013-08-01 01:47:39
【问题描述】:

请告知在 jQuery 中使用选择器的哪种方式更快:

$('.class1, .class2').html('');

$('.class1').html('');
$('.class2').html('');

【问题讨论】:

标签: javascript jquery performance jquery-selectors


【解决方案1】:

performance they seems to be almost same(7-8%)而言,但就可维护性而言,第一种方法会更好,因为没有重复代码

【讨论】:

    【解决方案2】:

    check Performance

    $('.class1, .class2').html('');不如

    1. 没有重复代码
    2. jQuery 构造函数只被调用一次,这使得它有点快。(+3-4%)

    【讨论】:

      猜你喜欢
      • 2019-04-09
      • 1970-01-01
      • 1970-01-01
      • 2020-07-17
      • 2016-04-24
      • 1970-01-01
      • 2016-04-02
      • 1970-01-01
      • 2020-01-15
      相关资源
      最近更新 更多