【问题标题】:IE conditional statements in Jade template engineJade 模板引擎中的 IE 条件语句
【发布时间】:2014-01-18 04:23:32
【问题描述】:

如何在 JADE 语言中转换以下 IE 条件语句:

<!--[if IE 8]> <html lang="en" class="ie8"> <![endif]-->
<!--[if IE 9]> <html lang="en" class="ie9"> <![endif]-->
<!--[if !IE]><!--> <html lang="en"> <!--<![endif]-->

我尝试了以下方法,但它不起作用:

//if IE 8
    html lang="en"  class="ie8"
//if IE 9
    html lang="en" class="ie9"
//if !IE
    html lang="en"
// <![endif]

它显示以下输出:

<!--if IE 8html lang="en"  class="ie8"
-->
<!--if IE 9html lang="en" class="ie9"
-->
<!--if !IEhtml lang="en"
-->
<!-- <![endif]-->

谁能指导我如何纠正它。

【问题讨论】:

  • 您是否尝试过将它们直接包含在您的模板中?
  • 你用的是哪个版本的翡翠和快递?
  • 您可以阅读更多关于 IE 条件 cmets - Jade 版本 1.0.0+ 和 0.35.0 中的方法以及 Jade 混合的用法here

标签: node.js express pug


【解决方案1】:

像这样使用它。这对我有用。

   | <!--[if IE 8]> <html lang="en" class="ie8"> <![endif]-->
   | <!--[if IE 9]> <html lang="en" class="ie9"> <![endif]-->
   | <!--[if !IE]><!--> <html lang="en"> <!--<![endif]-->

【讨论】:

    【解决方案2】:

    此代码应按预期工作。它适用于 Jade 版本,最高可达0.35.0

    请注意,最后一个html 元素必须是正确 Jade 元素(这就是为什么属性在括号(...) 内的原因)。前两个元素是 cmets 的一部分,因此应格式化为 formatted HTML 元素。

    //if IE 8
        <html lang="en" class="ie8">
    //if IE 9
        <html lang="en" class="ie9">
    //[if !IE]><!
    html(lang="en")
        //<![endif]
    

    页面中的输出如下:

    <!--[if IE 8]><html lang="en" class="ie8"><![endif]-->
    <!--[if IE 9]><html lang="en" class="ie9"><![endif]-->
    <!--[if !IE]><!--><html lang="en"><!--<![endif]-->
    

    编辑

    截至版本 1.0.0(发布于 2013 年 12 月 22 日)Jade 不再解析 cmets 内容,并且不再支持 IE 条件 cmets。

    新方法是使用格式良好的 IE 条件 cmets。这样做是安全的,因为现在 Jade 会忽略任何以 &lt; 开头的行。

    你的代码可以如下:

    <!--[if IE 8]><html class="ie8" lang="en"><![endif]-->
    <!--[if IE 9]><html lang="en" class="ie9"><![endif]-->
    <!--[if !IE]><!-->
    html(lang="en")
      <!--<![endif]-->
    

    请注意,html 元素将由 Jade 处理(及其所有功能,例如从请求处理方法中设置类名),因此您应该在 Jade 末尾附加 | &lt;/html&gt;文件。

    您也可以参考IE Conditional Comments in Jade Template Engine 帖子,了解将 Jade 与 IE 条件 cmets 混合使用的替代方法。

    我希望这会有所帮助。

    【讨论】:

      【解决方案3】:

      几个月前删除了对//if IE 8 条件注释语法的支持:Git Commit
      0.35 版是支持它们的最后一个版本; v1.0 是移除后的第一个版本。


      我一直在使用@Jayram 使用的文字样式;唯一的区别是条件逻辑 à la h5bp 和结束 html 标记:

      | <!--[if IE 8]>         <html lang="en" class="lt-ie9"> <![endif]-->
      | <!--[if gt IE 8]><!--> <html lang="en"> <!--<![endif]-->
      

      注意:记得用| &lt;/html&gt;关闭文档,因为初始的html标签不是Jade的自动关闭语法。

      【讨论】:

        猜你喜欢
        • 2013-03-14
        • 2013-07-22
        • 1970-01-01
        • 2014-11-21
        • 2011-11-14
        • 2021-11-05
        • 1970-01-01
        • 2012-09-04
        相关资源
        最近更新 更多