2012-01-05 10 views
-1

重複の可能性:
What does this mean in jquery $('#id', javascript_object);
What does $(''class for the same element', element) mean?
What does the second argument to $() mean?

誰もが何であるかを知っている:

$('element', $$).function(){...}; 

seen here

そして

$('element', this).function(){...}; 

seen here

+0

? –

+0

可能な複製[jquery $( '#id'、javascript_object);]でこれがどういう意味ですか?(http://stackoverflow.com/questions/3262974/what-does-this-mean-in-jquery-id-javascript -object)と[$( "同じ要素のクラス"、要素)の意味は何ですか?](http://stackoverflow.com/questions/6479300/what-does-class-for-the-same-element-要素平均)と[$()の第2引数は何を意味するのですか?](http://stackoverflow.com/questions/6979097/what-does-the-second-argument-to-mean) –

+0

文書から: "内部的にセレクタコンテキストは.find()メソッドで実装されているので、$( 'span'、this)は$(this).find( 'span')と等価です。 –

答えて

5
$('.pblabel', this).text(newVal + '%'); 

が実際に

$(this).find('.pblabel').text(newVal + '%'); 

と同じものです、それはそれは書き換えられ、内部で実行される方法です。これは「コンテキストセレクタ」と呼ばれます。 jQuery sourceから

[ドキュメント](http://api.jquery.com/jQuery/#jQuery1)に加えて、あなたが必要なん情報
// HANDLE: $(expr, $(...)) 
} else if (!context || context.jquery) { 
    return (context || rootjQuery).find(selector); 

// HANDLE: $(expr, context) 
// (which is just equivalent to: $(context).find(expr) 
} else { 
    return this.constructor(context).find(selector); 
} 
+0

これは非常に明確です、ありがとうございます。 –

5

thisまたは$$をコンテキストとして使用します。つまり、返されるすべての要素はその子孫でなければなりません。デフォルトはdocumentです。

+0

'$$' = 'this'? –

+0

@GG。いいえ、それはどんな変数でもかまいません。 '$'は変数名と関数名で有効です(したがって、jQueryの主な '$'関数)。 – Ryan