[已解决]使用JavaScript打印HTML表 [英] [Solved] Printing HTML table with JavaScript

查看:66
本文介绍了[已解决]使用JavaScript打印HTML表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个div

< div id ="aux"> aqui</div>

I have a div

<div id="aux">aqui</div>

linha = "<table cellspacing='0' cellpadding='0' border='0'>";
    linha = linha + "<tr>";
    linha = linha+ "<td>test</td>"; // just testing
    linha = linha + "</tr>";
    linha = linha + "</table>";
    document.getElementById('aux').innerHTML = linha;




但是不行.看起来在最后一行中,我有某种错误,因为如果我在该行之后放一个警报,我看不到它(但是如果放在它之前,我会看到它).

好的,我知道为什么.我将该代码放在一个函数中,并将其放在JS的第一行中.所以它在div出现之前就执行了,这就是为什么什么都不出现的原因.
对不起,我的英语.




But don''t work. Looks like in the last line I have some kind of error, because if I put an alert after that line I dont see it (but I see it if I place it before).

Ok I know why. I place that code inside a function and that function it''s in the first lines of JS. So it''s executed before before div is present, that''s why dont appear nothing.

Sorry for my English.

推荐答案

只需回答一下,便将其从未答复的列表中弹出.

由OP自己解决:
好吧,我知道为什么.我将该代码放在一个函数中,并将其放在JS的第一行中.所以它在div出现之前就执行了,这就是为什么什么都不出现的原因.
Just answering it to pop it out of unanswered list.

resolved by OP himself:
Ok I know why. I place that code inside a function and that function it''s in the first lines of JS. So it''s executed before before div is present, that''s why dont appear nothing.


这篇关于[已解决]使用JavaScript打印HTML表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆