【问题标题】:How can I wrap the table trs with divs on rails?如何在轨道上用 div 包裹表格 trs?
【发布时间】:2012-05-25 08:49:29
【问题描述】:

查看: <table><%= render(:partial => 'item') %></table>

部分: <div><tr><td>foo</td></tr></div>

我期待看到: <table><div><tr><td>foo</td></tr></div></table>

但我看到了: <div></div> <table><tr><td>foo</td></tr></table>

为什么?以及如何实现我的期望?

【问题讨论】:

  • 如果你显示你的代码会更容易。
  • 在部分文件中写入表格,例如
    foo
    并在视图中 'item') %>
  • 你为什么要&lt;div&gt;'s 围绕&lt;tr&gt;'s?这是有效的标记吗?
  • 你需要在partial中做
    foo

标签: html ruby-on-rails view html-table partial


【解决方案1】:

在 div 中包装 tds 和 trs 是不正确的。如果你想为 Capybara 添加一些 css 或标记一个特定的 td,你可以使用 id 或 class 属性inside td。类似&lt;td id="td_id" class="td_class"&gt;

【讨论】:

    【解决方案2】:

    Erb 不会生成您所期望的,因为那是不正确的 html。您不能将您的 trs 或 tds 包裹在 div 中。实际上,trs 只能是 table 元素的直接子元素或 tbody (html5) 的直接子元素。

    为什么还要将 trs 包装在 div 中?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-05
      • 2019-06-11
      • 1970-01-01
      • 1970-01-01
      • 2013-07-06
      相关资源
      最近更新 更多