如何将表JSP下载到txt

时间:2019-03-07 10:02:06

标签: javascript jsp

我正在尝试的

userDetails='';
$('table tbody tr').each(function(){
  var detail='(';
  $(this).find('td').each(function(){
    detail+=$(this).html()+',';
  });
  detail=detail.substring(0,detail.length-1);
  detail+=')';
 userDetails+=detail+"\r\n";
});
var a=document.getElementById('save');
a.onclick=function(){
    var a = document.getElementById("save");
    var file = new Blob([userDetails], {type: 'text/plain'});
    a.href = URL.createObjectURL(file);
    a.download = "data.txt";
}

一切顺利,但是,我的最后一个<td>是按钮,如何删除表格的最后一个<td>

预先感谢

1 个答案:

答案 0 :(得分:0)

在示例中使用jquery时,可以使用:

$('table tr').each(function (){
  $(this).find('td:last').remove();
})

它删除了表行中的最后一个<td>。请确保使用ID或类来限制表的范围,因为此脚本适用于页面上的所有表。