js遍历tr替换checkbox被选中里面td元素字符串插入
html部分:<tableclass="table-extends"><tr><td>1<td></tr><tr><td>2<td></tr></table>js部分代码:functionitemForm2(){varrand;varrand2;//遍历tr$('.table-extendstr
html部分:
js部分代码:
<table class="table-extends"> <tr><td>1<td></tr> <tr><td>2<td></tr> </table>
js部分代码:
function itemForm2(){ var rand ; var rand2 ; //遍历tr $('.table-extends tr').each(function(i){ var ischeck = $(this).children("td:eq(3)").find("input").attr('checked'); if(ischeck == "checked"){ //$('.table-extends').append($(this).clone()); //$(this).children("td:eq(3)").find("input").attr('checked',false); rand = new Date().getTime(); rand2 = $(this).children("td:eq(3)").find("input").val(); for(let key in $(this)){ //遍历对象 if(key == "context"){ doubleClick($(this)[key],rand2,rand); } } } }); } function doubleClick(tr,rand2,rand) { var cells = tr.cells; var cells2; var tr2 = '<tr class="extends-tr">'; var rand3 = rand.toString(); for(var i=0;i<cells.length;i++){ cells2 = cells[i].innerHTML; if(i==2){ tr2 = tr2 + '<td class="show">' + cells2.replace(rand2,rand3) + "</td>" }else{ tr2 = tr2 + "<td>" + cells2.replace(rand2,rand3) + "</td>" } } $('.table-extends').append(tr2+"</tr>"); }