【问题标题】:html - form table - invalid markuphtml - 表格 - 无效标记
【发布时间】:2012-09-09 02:21:17
【问题描述】:

我了解在表格行中放置表格是不正确的。不过,这样做似乎确实有实际原因。

我希望能够单独编辑每一行(ajax 等),因此每个 for 都是它自己的形式是有意义的。

以下是我需要如何布置表格和表单的功能,但标记无效。此外,haml/erb 实际上不会像这样处理标记(表单在第一个单元格内打开和关闭)。

我可以使用 display: table-cell 等,但我认为我正在显示的数据在语义上确实属于表格。

如何使用适当的标记完成相同的功能?

<table>
<thead>
  <tr>
    <th>id</th>
    <th>name</th> 
    <th>email</th>
    <th>phone</th>
    <th>address</th> 
  </tr>
</thead>
<tbody>
  <tr>
    <%= form_for person do |f| %>
      <td><%= id %></td>
      <td><%= f.text_field :name%></td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
    <% end %>
  </tr>
</tbody>
</table>

【问题讨论】:

    标签: html ruby-on-rails haml


    【解决方案1】:
    <table>
    <thead>
      <tr>
        <th>id</th>
        <th>name</th> 
        <th>email</th>
        <th>phone</th>
        <th>address</th> 
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>
          <%= form_for person do |f| %>
            <table>
              <tr>
                <td><%= id %></td>
                <td><%= f.text_field :name%></td>
                <td>...</td>
                <td>...</td>
                <td>...</td>
              </tr>
            </table>
          <% end %>
        </td>
      </tr>
    </tbody>
    </table>
    

    【讨论】:

    • 那行得通。不过,数据实际上并不需要嵌套表,所以它看起来仍然像一个布局黑客。并且可能需要更多的 CSS 来确保 TH 与它们各自的 TD 宽度相同。
    • 如果这是您的情况,那么我认为您要么需要为嵌套的 tds 恢复为 spans/divs,要么使用一种表单并解析数据服务器端以了解提交了哪一行。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-05
    相关资源
    最近更新 更多