如何使新插入的标签占据表格的总宽度
我有一个表,我正在动态插入一个新行。它仅包含在 td 上。但它只占用一个 td 宽度,如 此处
我怎样才能使新插入的tr占据表格的总宽度。
Here number of td s are not fixed.That is, it is not always 3.
这是我的 HTML
<table>
<tr><td>1</td><td>2</td><td>3</td></tr>
<tr id='a'><td>4</td><td>5</td><td>6</td></tr>
<tr><td>7</td><td>8</td><td>9</td></tr>
</table>
这是我的代码
$('<tr id="b" style="background-color:blue"><td >new</td></tr>').insertBefore($('#a'));
这里是 fiddle 来操作..
I have a table and I am inserting a new row dynamically. It contains only on td. But it is occupying only one td width as here
How can i make newly inserted tr to occupy the total width of the table.
Here number of td s are not fixed.That is, it is not always 3.
Here is my HTML
<table>
<tr><td>1</td><td>2</td><td>3</td></tr>
<tr id='a'><td>4</td><td>5</td><td>6</td></tr>
<tr><td>7</td><td>8</td><td>9</td></tr>
</table>
Here is my code
$('<tr id="b" style="background-color:blue"><td >new</td></tr>').insertBefore($('#a'));
Else here is the fiddle to put hands on..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
将
colspan
添加到元素:
http ://jsfiddle.net/WAuw4/5/
编辑
如果您不知道表格中的单元格数量:
Add a
colspan
to the<td>
element:http://jsfiddle.net/WAuw4/5/
EDIT
If you don't know the number of cells in the table:
您可以在新的
td
中添加colspan=3
示例:http://jsfiddle.net/WAuw4/4/
下面是关于
colspan
属性的更多信息:http://reference.sitepoint.com/html/td/colspan编辑:< /strong>
根据您的评论
我会这样做
检查第一行中的
td
数量。将其添加到您的colspan
示例: http://jsfiddle .net/WAuw4/7/
You could add
colspan=3
in your newtd
Example: http://jsfiddle.net/WAuw4/4/
Here's a bit more on the
colspan
attribute: http://reference.sitepoint.com/html/td/colspanEDIT:
Based on your comment
I would do this
Check the number of
td
in the first row. Add that to yourcolspan
Example: http://jsfiddle.net/WAuw4/7/
像这样插入
colspan="3"
insert
colspan="3"
like this使用
Colspan
调整行中td的跨度。我已经检查过你了,jsfiddle..
你应该有一些固定或可预测的
计数,否则你如何管理这个..如果你想实现这种方法,那么就在
的地方>
使用Use
Colspan
to adjust the span of the td in the row.I have checked on you jsfiddle..
you should have some fixed or predictable count of
<td>
else how can you manage this.. if you want to implement such approach then on the place of<td>
use<div>