公告
财富商城
积分规则
提问
发文
2019-07-24 04:24发布
可以哭但决不认输i
I have seen it here. What is meant by tbl in the following statement? What does it imply?
tbl
var rows = $('tr', tbl);
The tbl in the above is another dom element. This is passed in as the (optional parameter) context:
context
jQuery( selector [, context ] )
...for the selector, in this case 'tr'.
selector
'tr'
So essentially this:
$('tr', tbl);
says return me everything that matches the selector 'tr' in the element(s) tbl.
So given
<table> <tr>first</tr> <table> <table id="test"> <tr>second</tr> </table>
This returns varying results:
//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
This pattern is using jQuery context. Your query is used to find the rows within the table.
var tbl = $("table#tableId"); // this line provides the context var rows = $("tr", tbl); // finding all rows within the context
This is equivalent to writing
var rows = tbl.find("tr")
There is good explanation on using jQuery context in this SO Question here
最多设置5个标签!
The
tbl
in the above is another dom element. This is passed in as the (optional parameter)context
:...for the
selector
, in this case'tr'
.source
So essentially this:
says return me everything that matches the selector
'tr'
in the element(s)tbl
.Example
So given
This returns varying results:
This pattern is using jQuery context. Your query is used to find the rows within the table.
This is equivalent to writing
There is good explanation on using jQuery context in this SO Question here