本文介绍了将以前的行数据添加到动态生成的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我有一张桌子。选择变量的onchange,它会生成行。 我想要做的是,我在第一行中写入的数据应该被复制到生成的行中。 这是我的表和Java脚本。 < form> < table border =1id =engagementments> < tr> < th>< input type =checkboxonclick =checkAll(this)>< / th> < th>组织< / th> < th> Project< / th> < th>产品< / th> < th>活动< / th> < / tr> < tr> < td>< input type =checkboxonclick =checkAll(this)>< / td> < td>< input type =text/>< / td> < td>< input type =text/>< / td> < td>< input type =text/>< / td> < td>< input type =text/>< / td> <! - < td>< input type =text/>< / td> < td>< input type =text/>< / td> < td>< input type =text/>< / td> < td>< input type =text/>< / td> < td>< input type =text/>< / td> - > < / tr> < / table> < option value =>添加更多与上述相同数据的行< / option> < option value =1> 1更多< / option> < option value =2> 2更多< / option> < option value =3> 3更多< / option> < option value =4> 4更多< / option> < option value =5> 5更多< / option> < / select> < / form> < script language =javascript> 函数addrow(tableID) { var table = document.getElementById(tableID); var rowCount = table.rows.length; var row = table.insertRow(rowCount); var colCount = table.rows [0] .cells.length; var e = document.getElementById(mode); var strUser = e.options [e.selectedIndex] .value; (var i = 0; i {b $ b(var j = 0; j { var newcell = row.insertCell(i); newcell.innerHTML = table.rows [1] .cells [i] .innerHTML; } var row = table.insertRow(rowCount); } } < / script> 解决方案如果您已经在使用jQuery, - $ b $ $(#mode)。on('change',function(){ var rows = parseInt(this.value); var lastRow; for(var i = 0; i lastRow = $('#engagementments tr')last ).clone(); $('#engagements tr')。last()。after(lastRow); } }); 演示 ---->> http://jsfiddle.net/jW6eL/ I have a table. onchange of select variable, it generates rows.what i want to do is that, the data which i wrote in the first row, should be copied in the generated rows.This is my Table and the java script. <form> <table border = "1" id = "engagements"> <tr> <th><input type="checkbox" onclick="checkAll(this)"></th> <th>Organization</th> <th>Project</th> <th>Product</th> <th>Activity</th> </tr> <tr> <td><input type="checkbox" onclick="checkAll(this)"></td> <td><input type = "text"/></td> <td><input type = "text"/></td> <td><input type = "text"/></td> <td><input type = "text"/></td> <!-- <td><input type = "text"/></td> <td><input type = "text"/></td> <td><input type = "text"/></td> <td><input type = "text"/></td> <td><input type = "text"/></td> --> </tr> </table> <select name = "mode" id = "mode" onchange="addrow('engagements')"> <option value="">Add More Rows with Same Data as Above</option> <option value="1">1 More</option> <option value="2">2 More</option> <option value="3">3 More</option> <option value="4">4 More</option> <option value="5">5 More</option> </select></form><script language="javascript"> function addrow(tableID) { var table = document.getElementById(tableID); var rowCount = table.rows.length; var row = table.insertRow(rowCount); var colCount = table.rows[0].cells.length; var e = document.getElementById("mode"); var strUser = e.options[e.selectedIndex].value; for (var j = 0; j < strUser; j++) { for (var i = 0; i < colCount; i++) { var newcell = row.insertCell(i); newcell.innerHTML = table.rows[1].cells[i].innerHTML; } var row = table.insertRow(rowCount); } }</script> 解决方案 If you are already using jQuery , You can do this -$("#mode").on('change', function () { var rows = parseInt(this.value); var lastRow; for (var i = 0; i < rows; i++) { lastRow = $('#engagements tr').last().clone(); $('#engagements tr').last().after(lastRow); }});Demo ----> http://jsfiddle.net/jW6eL/ 这篇关于将以前的行数据添加到动态生成的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-05 13:20