我的html结构如下:
<table class="table">
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Category</th>
</tr>
</thead>
<tbody>
<tr>
<td>John</td>
<td>john@live.nl</td>
<td>
<form method="post" action="admin.php>
<input type="text" ........
<input type="text" ........
<button type="submit" name="change_category">Update</button>
</form>
</td>
</tr>
</tbody>
</table>
当我在验证器https://validator.w3.org/中检查它时;它不会给我一个错误。但是我不确定这是否正确...
因为,根据这个主题:Form inside a table;这是不允许的
答案 0 :(得分:1)
是的。可以将表格放在表格的<td>
标签内。
upd。在上一个示例表单中,将表单放置在<tr>
中不是最佳做法,是的,但是我发现在您的代码中,您将表单放置在<td>
中是完全可以的。
答案 1 :(得分:1)
是的,您可以在td
标签内添加表格,对于哪个标签可以作为form标签的父级没有任何限制,只要它包装在开始和结束标签内即可。
当您有这样的表时,这是常见的用例
<table>
<tr>
<td>ID></td>
<td>Name</td>
<td>Description</td>
<td>Actions</td>
</tr>
<tr>
<td>1</td>
<td>First Article</td>
<td>Description for first article</td>
<td>
<a href="...">View</a>
<form method="post" action="...">
<input type="submit" value="Delete">
</form>
</td>
</tr>
</table>
在“操作”列中,我具有允许删除表中特定行中的数据的操作,并且该操作是使用POST方法执行的