for (var i = 0; row = tableAppointment.rows[i]; i++) {
for (var j = 0; col = row.cells[j]; j++) {
//iterate through columns
//columns would be accessed using the "col" variable assigned in the for loop.
}
}
如何循环访问其第三个单元格具有rowspan
属性的每一行。
这将为您提供包含此类元素的所有<tr>
:
$('td:nth-child(3)[rowspan]').parent()
http://jsfiddle.net/52aR2/1/演示
$("tr").filter( function() {
return this.cells[2].hasAttribute("rowspan");
});
http://jsfiddle.net/52aR2/2/
或
for (var i = 0; row = tableAppointment.rows[i]; i++) {
if( row.cells[2].hasAttribute("rowspan") {
//This is a row that matches
}
}
这样的东西应该有效
$('tr').filter( function() {
return $('td:eq(2)',this).attr( 'rowspan' ) !== undefined;
} ).css( 'border', '1px solid red');
http://jsfiddle.net/9gMRk/
你可以
这样做:
if (cell[2].hasAttribute('rowspan')) {
// do something here
}
用途element.hasAttribute()
Array.prototype.slice.call(tableAppointment.rows).
filter(function(row) { return row.cells[2].rowSpan > 1; }).
forEach(function(row) {
// do something with row
});
哇,看妈妈,没有jQuery!
这实际上是正确的答案。
$('td:nth-child(3)[rowspan]').parent()
$('td:nth-child(3)[rowspan]').parent()