使用带有context参数的选择器而不是指定它会更快吗?
示例:
var source = $('option:selected', 'select#source').text();
VS
var source = $('select#source option:selected').text();
哪个更快,为什么?
答案 0 :(得分:3)
如果context参数是缓存值而不是选择器,那么context参数主要是有益的:
var source = $('select#source');
var selected = $('option:selected', source);
var nonselected = $('option:not(:selected)', source);