私はここでそれを見ました。tbl
次の文の意味は何ですか? それは何を意味しますか?
var rows = $('tr', tbl);
私はここでそれを見ました。tbl
次の文の意味は何ですか? それは何を意味しますか?
var rows = $('tr', tbl);
上記tbl
の は別の dom 要素です。これは (オプションのパラメーター) として渡されますcontext
。
jQuery( selector [, context ] )
... selector
、この場合は'tr'
.
だから本質的にこれ:
$('tr', tbl);
element(s) のセレクターに一致するすべてのものを返すと言い'tr'
tbl
ます。
与えられた
<table>
<tr>first</tr>
<table>
<table id="test">
<tr>second</tr>
</table>
これはさまざまな結果を返します。
//context is global
$('tr') => first & second
//restrict the context to just the second table
//by finding it and passing it into the selector
var tbl = $('#test');
$('tr', tbl) => just second
このパターンは jQuery コンテキストを使用しています。クエリは、テーブル内の行を見つけるために使用されます。
var tbl = $("table#tableId"); // this line provides the context
var rows = $("tr", tbl); // finding all rows within the context
これは、書き込みに相当します。
var rows = tbl.find("tr")