0

idjQuery関数の1回の呼び出しでいくつかをグループ化するか、行ごとに呼び出すと(idafter ) 、パフォーマンスが向上するかどうか疑問に思っていましたid

とりあえずこんな感じです。

$('#culetType').combobox();
$('#girdle').combobox();
$('#polishLinesIntensity').combobox();
$('#burnmarksIntensity').combobox();
$('#scratchesIntensity').combobox();
$('#damagesIntensity').combobox();

したがって、これを修正するとパフォーマンスが向上します。

$('#culetType, #girdle, #polishLinesIntensity, #burnmarksIntensity, #scratchesIntensity, #damagesIntensity').combobox();

読むのが楽しくないという事実に加えて。

私はそれらすべてのid'saを与えることができることを知っclassています.

それで、それはパフォーマンスの向上になるでしょうか?

4

2 に答える 2

1

In newer browsers using a single selector will give a slight performance boost, because jQuery uses the built in method to run the selector. Creating a single jQuery object and do the operation on all elements in it is slightly faster than creating a bunch of jQuery objects.

In older browsers it will be slightly faster to parse the selector containing a single id, but it will be slightly slower to create multiple jQuery objects, so the methods would perform about the same.

于 2013-04-08T12:29:00.107 に答える
1

私が知っているように、書き込み$()は毎回DOMを呼び出します。したがって、いくつかの要素をより適切に呼び出す場合でも、次のようにします。

el = $('#myEl');
el.firstAction();
el.secondAction();

それ以外の

$('#myEl').firstAction();
$('#myEl').secondAction();

したがって、1回の呼び出しでより速く動作すると思います$('...,...,...')が、ブーストは小さくなります。

ただし、1回の呼び出しの場合、次のようなことはできないことを覚えておく必要があります。

$('#culetType').combobox();
$('#girdle').combobox({property: false});
$('#polishLinesIntensity').combobox();
于 2013-04-08T12:49:36.700 に答える