用js 把table 特定值所在的行 (tr) 删除,然後导出excel 5
我想把所有的table中隐藏的tr都删除,然後导出excel但导出後,还是有table中隐藏的tr.我的code是这样:<scriptlanguage="javascri...
我想把所有的 table 中隐藏的 tr 都删除,然後导出excel
但导出後,还是有 table 中隐藏的 tr .
我的code 是这样:
<script language="javascript" type="text/javascript">
function method1(tableid) {
var curTbl = document.getElementById(tableid);
var oXL = new ActiveXObject("Excel.Application");
var oWB = oXL.Workbooks.Add();
var oSheet = oWB.ActiveSheet;
var sel = document.body.createTextRange();
sel.moveToElementText(curTbl);
sel.select();
sel.execCommand("Copy");
oSheet.Paste();
oXL.Visible = true;
}
var idTmr ;
function Cleanup() {
window.clearInterval(idTmr);
CollectGarbage();
}
function DelRows()
{
var trs = document.getElementById('tableExcel').getElementsByTagName('tr');
for(var i=0;i<trs.length;i++){
if(trs[i].style.display =='none'){
trs[i].parentElement.removeChild(trs[i]);
}
}
}
</script>
</head>
<body>
<table id="tableExcel" width="100%" border="1" cellspacing="0" cellpadding="0">
<tr>
<td colspan="5" align="center">html </td>
</tr>
<tr style="display:none" >
<td >AAA</td>
<td>BBB</td>
<td>CCC</td>
<td>DDD</td>
<td>EEE</td>
</tr>
<tr style="display:none" >
<td >AAA</td>
<td>BBB</td>
<td>CCC</td>
<td>DDD</td>
<td>EEE</td>
</tr>
<tr style="display:none" >
<td >AAA</td>
<td>BBB</td>
<td>CCC</td>
<td>DDD</td>
<td>EEE</td>
</tr> <tr style="display:none" >
<td >AAA</td>
<td>BBB</td>
<td>CCC</td>
<td>DDD</td>
<td>EEE</td>
</tr>
<tr style="display:none" >
<td >AAA</td>
<td>BBB</td>
<td>CCC</td>
<td>DDD</td>
<td>EEE</td>
</tr>
<tr style="display:none" >
<td >AAA</td>
<td>BBB</td>
<td>CCC</td>
<td>DDD</td>
<td>EEE</td>
</tr>
<tr style="display:none" >
<td >AAA</td>
<td>BBB</td>
<td>CCC</td>
<td>DDD</td>
<td>EEE</td>
</tr>
<tr style="display:none" >
<td >AAA</td>
<td>BBB</td>
<td>CCC</td>
<td>DDD</td>
<td>EEE</td>
</tr>
<tr style="display:none" >
<td >AAA</td>
<td>BBB</td>
<td>CCC</td>
<td>DDD</td>
<td>EEE</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
</tr>
<tr>
<td>aaa</td>
<td>bbb</td>
<td>ccc</td>
<td>ddd</td>
<td>eee</td>
</tr>
<tr style="display:none" >
<td >AAA</td>
<td>BBB</td>
<td>CCC</td>
<td>DDD</td>
<td>EEE</td>
</tr>
<tr style="display:none" >
<td >AAA</td>
<td>BBB</td>
<td>CCC</td>
<td>DDD</td>
<td>EEE</td>
</tr>
<tr style="display:none" >
<td >AAA</td>
<td>BBB</td>
<td>CCC</td>
<td>DDD</td>
<td>EEE</td>
</tr>
<tr style="display:none" >
<td >AAA</td>
<td>BBB</td>
<td>CCC</td>
<td>DDD</td>
<td>EEE</td>
</tr>
<tr>
<td>FFF</td>
<td>GGG</td>
<td>HHH</td>
<td>III</td>
<td>JJJ</td>
</tr>
</table>
<button onclick="DelRows();method1('tableExcel')">1</button> 展开
但导出後,还是有 table 中隐藏的 tr .
我的code 是这样:
<script language="javascript" type="text/javascript">
function method1(tableid) {
var curTbl = document.getElementById(tableid);
var oXL = new ActiveXObject("Excel.Application");
var oWB = oXL.Workbooks.Add();
var oSheet = oWB.ActiveSheet;
var sel = document.body.createTextRange();
sel.moveToElementText(curTbl);
sel.select();
sel.execCommand("Copy");
oSheet.Paste();
oXL.Visible = true;
}
var idTmr ;
function Cleanup() {
window.clearInterval(idTmr);
CollectGarbage();
}
function DelRows()
{
var trs = document.getElementById('tableExcel').getElementsByTagName('tr');
for(var i=0;i<trs.length;i++){
if(trs[i].style.display =='none'){
trs[i].parentElement.removeChild(trs[i]);
}
}
}
</script>
</head>
<body>
<table id="tableExcel" width="100%" border="1" cellspacing="0" cellpadding="0">
<tr>
<td colspan="5" align="center">html </td>
</tr>
<tr style="display:none" >
<td >AAA</td>
<td>BBB</td>
<td>CCC</td>
<td>DDD</td>
<td>EEE</td>
</tr>
<tr style="display:none" >
<td >AAA</td>
<td>BBB</td>
<td>CCC</td>
<td>DDD</td>
<td>EEE</td>
</tr>
<tr style="display:none" >
<td >AAA</td>
<td>BBB</td>
<td>CCC</td>
<td>DDD</td>
<td>EEE</td>
</tr> <tr style="display:none" >
<td >AAA</td>
<td>BBB</td>
<td>CCC</td>
<td>DDD</td>
<td>EEE</td>
</tr>
<tr style="display:none" >
<td >AAA</td>
<td>BBB</td>
<td>CCC</td>
<td>DDD</td>
<td>EEE</td>
</tr>
<tr style="display:none" >
<td >AAA</td>
<td>BBB</td>
<td>CCC</td>
<td>DDD</td>
<td>EEE</td>
</tr>
<tr style="display:none" >
<td >AAA</td>
<td>BBB</td>
<td>CCC</td>
<td>DDD</td>
<td>EEE</td>
</tr>
<tr style="display:none" >
<td >AAA</td>
<td>BBB</td>
<td>CCC</td>
<td>DDD</td>
<td>EEE</td>
</tr>
<tr style="display:none" >
<td >AAA</td>
<td>BBB</td>
<td>CCC</td>
<td>DDD</td>
<td>EEE</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
</tr>
<tr>
<td>aaa</td>
<td>bbb</td>
<td>ccc</td>
<td>ddd</td>
<td>eee</td>
</tr>
<tr style="display:none" >
<td >AAA</td>
<td>BBB</td>
<td>CCC</td>
<td>DDD</td>
<td>EEE</td>
</tr>
<tr style="display:none" >
<td >AAA</td>
<td>BBB</td>
<td>CCC</td>
<td>DDD</td>
<td>EEE</td>
</tr>
<tr style="display:none" >
<td >AAA</td>
<td>BBB</td>
<td>CCC</td>
<td>DDD</td>
<td>EEE</td>
</tr>
<tr style="display:none" >
<td >AAA</td>
<td>BBB</td>
<td>CCC</td>
<td>DDD</td>
<td>EEE</td>
</tr>
<tr>
<td>FFF</td>
<td>GGG</td>
<td>HHH</td>
<td>III</td>
<td>JJJ</td>
</tr>
</table>
<button onclick="DelRows();method1('tableExcel')">1</button> 展开
2个回答
展开全部
var trs = document.getElementById('delrow').getElementsByTagName('tr');
for(var i=0;i<trs.length;i++){
if(trs[i].style.display =='none'){
trs[i].parentElment.removeChild(trs[i]);
// document.getElementById('delrow').removeRow(trs[i]);
}
}
用jquery的话就比较简单了~
如下:
$('#delrow tr:hidden').remove();
追问
你有否看我例. 我已用了你所給的答案啦
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询