将表行添加到表的底部

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了将表行添加到表的底部相关的知识,希望对你有一定的参考价值。

Great little snippit to add a to the bottom of a table. Note the use of the context in the jQuery e.g var n = $('tr:last td', this).length; Will have to use this in the future, very good to know!
  1. /*
  2. Add a new table row to the bottom of the table
  3. */
  4.  
  5. function addTableRow(jQtable){
  6. jQtable.each(function(){
  7. var $table = $(this);
  8. // Number of td's in the last table row
  9. var n = $('tr:last td', this).length;
  10. var tds = '<tr>';
  11. for(var i = 0; i < n; i++){
  12. tds += '<td> </td>';
  13. }
  14. tds += '</tr>';
  15. if($('tbody', this).length > 0){
  16. $('tbody', this).append(tds);
  17. }else {
  18. $(this).append(tds);
  19. }
  20. });
  21. }

以上是关于将表行添加到表的底部的主要内容,如果未能解决你的问题,请参考以下文章