这里的人经常建议缓存jQuery从DOM元素创建的对象,就像使用以下代码一样:
jQuery
DOM
$('#container input').each(function() { $(this).addClass('fooClass'); $(this).attr('data-bar', "bar"); $(this).css('background-color', 'red'); });
javascript performance jquery
javascript ×1
jquery ×1
performance ×1