【问题标题】:Haml %noscript tag generating wrong html resultHaml %noscript 标记生成错误的 html 结果
【发布时间】:2019-04-25 12:39:20
【问题描述】:

这是我的 ruby​​ on rails / haml 代码

%noscript
  %iframe{ :src => "https://www.googletagmanager.com/ns.html?id=#{key}", :style => "display:none;visibility:hidden",:height => "0", :width => "0"}

这是预期的 html 输出。

<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXXXX"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>

但它会生成

<noscript>
"
<iframe height='0' src='https://www.googletagmanager.com/ns.html?id=GTM-XXXXXX' style='display:none;visibility:hidden' width='0'></iframe>
"
</noscript>

如您所见,iframe 由 "" 引号包裹。为什么会这样? 我也尝试使用 src: "..." 而不是使用 :src => "..." 但 id 不起作用。

【问题讨论】:

    标签: ruby-on-rails ruby haml


    【解决方案1】:

    您如何查看生成的 HTML?看起来您正在使用浏览器检查器,它在显示时添加引号。它们不会出现在实际的 HTML 中。如果您使用“查看源代码”而不是元素检查器,您应该会看到您所期望的。

    【讨论】:

    • 是的,我就是这样做的...感谢您提供的信息
    猜你喜欢
    • 1970-01-01
    • 2012-10-03
    • 2018-12-12
    • 2017-01-28
    • 1970-01-01
    • 2020-01-03
    • 2021-05-26
    • 2020-03-15
    • 1970-01-01
    相关资源
    最近更新 更多