[英]dynamic table row select and bind
I have a table (id=tbl). 我有一张桌子(id = tbl)。 and do some job on each row when loading. 并在加载时在每一行上做一些工作。
var loadCheck = function(){
$('#sTable tbody tr').each(function () {
do some job...
});
}
$(document).ready(function () {
loadCheck();
});
It works fine. 工作正常。 But there is a button in that page. 但是该页面上有一个按钮。 When click the whole table will be recreate dynamically. 单击后,整个表将动态重新创建。 This time table rows won't be selected. 不会选择此时间表行。
The Html code is like below: HTML代码如下所示:
<div id="sTable" style="padding-top:10px;">
<table id='tbl' border="1" class="table table-hover">
<tr>
<th>Col1</th>
<th>Col2</th>
<th>Col3</th>
</tr>
<tbody>
<tr>
<td>xxx</td>
<td>xxx</td>
<td>xxx</td>
</tr>
</tbody>
</table>
since the div sTable is static but tbl is dynamic. 由于div sTable是静态的,而tbl是动态的。 So I bind the tbody to sTable. 所以我将tbody绑定到sTable。 but still not work. 但仍然无法正常工作。 I was tols use $("sTable").on("load"," tbody tr",function(){}) may be good for dynamic binding. 我曾经使用$(“ sTable”)。on(“ load”,“ tbody tr”,function(){})进行动态绑定。 but how to handle the "each" function. 但是如何处理“每个”功能。 Any suggestion? 有什么建议吗?
You could wrap your .each()
in another function like: 您可以将.each()
包装在另一个函数中,例如:
function iteration() {
$('#sTable tbody tr').each(function () {
// do some job...
});
};
then call it on page load to initialize it: 然后在页面加载时调用它以对其进行初始化:
iteration();
and then also call it inside your button .click()
function. 然后在按钮.click()
函数中调用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.