gpt4 book ai didi

php - 将单元格插入表中?

转载 作者:行者123 更新时间:2023-11-29 15:03:37 24 4
gpt4 key购买 nike

如何将单元格插入表格中?

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

就我而言,如何将单元格插入到距行开头 150 像素的行中?

示例:

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

最佳答案

最简单的方法是在将其发送给用户之前生成带有额外单元格的表格。

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

<table>
<tr>
<td>foo</td>
<td id="inserthere">bar</td>
</tr>
</table>

您可以使用以下内容:

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>

如果你要像这样对 DOM 树进行批量操作,你最好使用 jQuery 或 MooTools,它们可以在一行代码中完成类似的操作,并且可以让你更好地控制操作的位置新节点被插入(之前、之后、顶部、底部等)。

至于 150 像素偏移,您可以使用 CSS 样式来覆盖它。一些填充或边距就可以解决问题。

还请记住,如果您要插入的表格使用行或列跨度,则新单元格无疑会严重破坏布局。

关于php - 将单元格插入表中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2623071/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com