javascript动态生成table
转载于http://blog.csdn.net/cctt_1/archive/2008/01/21/2057233.aspxjavascript动态生成Table是在迫不得以的情况下使用。因为表格会耗费大量的时间进行重绘。 而且如果窗口变化了,还会引起意想不到的格式变化。所以最好不要使用。
先在<form>中添加一个<div id='divTable'></div>下面就可以使用javascript代码来做这个事情:
<div style="padding-right: 5.4pt; padding-left: 5.4pt; background: #e6e6e6; padding-bottom: 4px; width: 95%; padding-top: 4px;">http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.giffunction createTable(divName)
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif var div = document.getElementById(divName);
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif var table = document.createElement("table");//创建table
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif var row = table.insertRow();//创建一行
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif var cell = table.insertCell();//创建一个单元
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif cell.width = "10";//更改cell的各种属性
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif cell.style.backgroundColor = "#999999";
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif}
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif
页:
[1]