Php 将单元格插入表格?

Php 将单元格插入表格?,php,javascript,mysql,html,Php,Javascript,Mysql,Html,如何将单元格插入表中 例如,我使用MySql和PHP从数据库检索数据,然后如何将单元格插入已编写脚本的表中 在我的例子中,如何将一个单元格插入到距行开始150像素的行中 例如: ___________________________________________ | <--150px--> |cell| | ___________________________________________ ||细胞|| 最简单的方法是,在将表格发

如何将单元格插入表中

例如,我使用MySql和PHP从数据库检索数据,然后如何将单元格插入已编写脚本的表中

在我的例子中,如何将一个单元格插入到距行开始150像素的行中

例如:

 ___________________________________________
| <--150px-->  |cell|                      |
___________________________________________
||细胞||

最简单的方法是,在将表格发送给用户之前,先生成已放置了额外单元格的表格

之后,您必须使用一些Javascript将新单元格动态插入页面的DOM树中。给出如下表片段:

<table>
<tr>
    <td>foo</td>
    <td id="inserthere">bar</td>
</tr>
</table>
这将给你:

<table>
<tr>
    <td>foo</td>
    <td>this is the new cell</td>
    <td id="inserthere">bar</td>
</tr>
</table>

福
这是新的细胞
酒吧
如果您打算像这样对DOM树进行批量操作,最好使用jQuery或MooTools,它们可以在一行代码中完成类似的操作,另外还可以让您更好地控制新节点的插入位置(之前、之后、顶部、底部等等)

至于150像素的偏移量,您可以使用CSS样式来覆盖它。一些填充或空白就可以了

还要记住,如果要插入的表使用行或列跨距,那么新单元格无疑会严重破坏布局

var td = document.createElement('td');
td.nodeValue = 'this is the new cell';
document.getElementById('inserthere').insertBefore(td);
<table>
<tr>
    <td>foo</td>
    <td>this is the new cell</td>
    <td id="inserthere">bar</td>
</tr>
</table>