0
我像个表的div,我想通过jQuery的每个格列循环和收集的列值(也行ID)循环通过DIV行和收集行的id和列值
我该怎么做?代码是在此jsffiddle
https://jsfiddle.net/DTcHh/24064/
HTML
<div id="tasksTableDiv">
<div class="row taskRow" id="1">
<div id="description_1"
class="col-sm-2 taskDescriptionCol">Description 1
</div>
<div id="colour_1"
class="col-sm-2 taskColourCol">Blue
</div>
</div>
<div class="row taskRow" id="2">
<div id="description_2"
class="col-sm-2 taskDescriptionCol">Description 2
</div>
<div id="colour_1"
class="col-sm-2 taskColourCol">Red
</div>
</div>
</div>
<button id="loopButton" type="button"
class="btn btn-sm btn-primary">Loop</button>
JS
$('#loopButton').on('click',function() {
var ids = [];
var row = $('.taskRow');
$.each(row, function() {
// get the id of each row and get the description and colour
// ids.push(push the id you got);
console.log("in loop" + row.html());
});
});
你'$。每()'函数是不是做与它的遍历的元素什么关系吧。 'row.html()'返回第一行的HTML,而不是循环的当前行。 – Barmar