Now there is a table, each tr has a number as class. Assume that a tr is selected. How to get all tr whose class is less than or equal to the selected tr?
怪我咯2017-05-18 10:47:42
You should not use tr numbers as classes, because there are many classes bound to tr. You can completely bind numbers to data-num. The logic is probably as follows. Maybe some selectors are not written so accurately
html table:
<table id='example_table'>
<thead>
<th>1<th>
<th>2<th>
<th>3<th>
</thead>
<tbody>
<tr data-num="1">
<td>1<td>
<td>2<td>
</tr>
<tr data-num="2">
<td>1<td>
<td>2<td>
</tr>
<tr data-num="3">
<td>1<td>
<td>2<td>
</tr>
</tbody>
</table>
js:
$('#example_table tr').on('click', function(e) {
var select_tr_num = $this.data('num');
var request_trs = [];
$.each($('#example_table tr'), function(i, obj) {
if (!obj.data('num') > select_tr_num) {
select_tr_num.push(obj);
}
});
console.log(request_trs );
});
巴扎黑2017-05-18 10:47:42
What the first floor said is right. Generally, no one names a class with a number. They usually add a custom attribute
PHP中文网2017-05-18 10:47:42
Traverse the values of all classes and then compare and store them. (ps: But using numbers as classes is not very standard.)