如何在玉石中添加html标签条件?

zlo*_*log 26 html internet-explorer node.js pug

,我要放在一个html标记条件按照这种方法,这使在

<!--[if lt IE 7 ]> <html class="ie6"> <![endif]-->
<!--[if IE 7 ]>    <html class="ie7"> <![endif]-->
<!--[if IE 8 ]>    <html class="ie8"> <![endif]-->
<!--[if IE 9 ]>    <html class="ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html class=""> <!--<![endif]-->
Run Code Online (Sandbox Code Playgroud)

在html文件的顶部.

我试过了

//[if lt IE 7]> <html class="no-js ie6 oldie" lang="en"> <![endif]
//[if IE 7]>    <html class="no-js ie7 oldie" lang="en"> <![endif]
//[if IE 8]>    <html class="no-js ie8 oldie" lang="en"> <![endif]
//[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]
  head
    ...
Run Code Online (Sandbox Code Playgroud)

但是jade忽略了html标记,并且没有在end </html>标记中写入.这是无效的html,导致IE根本没有显示任何内容.

这有什么办法吗?

我想我只会使用一个javascript解决方案,如果没有办法.

小智 21

这个方法适用于关闭html标记:

!!! 5
//if lt IE 7
    <html class="no-js lt-ie9 lt-ie8 lt-ie7">
//if IE 7
    <html class="no-js lt-ie9 lt-ie8">
//if IE 8
    <html class="no-js lt-ie9">
// [if gt IE 8] <!
html(class="no-js", lang="en")
    // <![endif]
    head
        title= title

    body!= body
Run Code Online (Sandbox Code Playgroud)

来自:https://gist.github.com/kmiyashiro/1140425#comment-675550

更新:

正如kumar-harsh所指出的,这种行为现在已被折旧,如果你需要这个功能,你现在应该使用常规的html:

<!--[if IE]>
  <html class="ie">
<![endif]-->
<![if !IE]>
  <html class="not-ie">
<![endif]>
</html>
Run Code Online (Sandbox Code Playgroud)

来自:https://github.com/visionmedia/jade/issues/1345?source = cc #issuecomment-31920732


小智 17

这是你正在寻找的,它也将提供结束html标记.

!!! 5
//[if lt IE 7]><html lang="en" class="no-js oldie lt-ie9 lt-ie8 lt-ie7"><![endif]
//[if IE 7]><html lang="en" class="no-js oldie lt-ie9 lt-ie8"><![endif]
//[if IE 8]><html lang="en" class="no-js oldie lt-ie9"><![endif]
//[if gt IE 8]><!
html(class='no-js', lang='en')
  //<![endif]
  head
Run Code Online (Sandbox Code Playgroud)


Fre*_*ric 11

只需使用此语法,请注意不同的缩进:

!!! 5
| <!--[if lt IE 7]> <html class="ie6 oldie" lang="en"> <![endif]-->
| <!--[if IE 7]>    <html class="ie7 oldie" lang="en"> <![endif]-->
| <!--[if IE 8]>    <html class="ie8 oldie" lang="en"> <![endif]-->
| <!--[if gt IE 8]><!--> <html lang="en"> <!--<![endif]-->
head
  …
Run Code Online (Sandbox Code Playgroud)


Tom*_*Tom 8

在版本1.0.0(2013年12月22日发布)中,Jade不再解析评论内容,并且已删除对IE条件注释的支持(//if lt IE 7不会在版本0.35.0及以下版本中工作).

新方法是使用格式良好的IE条件注释.所以为了生成上面的IE条件注释,Jade模板必须如下:

<!--[if lt IE 7 ]> <html class="ie6"> <![endif]-->
<!--[if IE 7 ]>    <html class="ie7"> <![endif]-->
<!--[if IE 8 ]>    <html class="ie8"> <![endif]-->
<!--[if IE 9 ]>    <html class="ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!-->
html(class="") 
  <!--<![endif]-->
  ...
Run Code Online (Sandbox Code Playgroud)

请注意,前四个html元素是格式良好的HTML元素.最后一个使用Jade语法.最后的评论<!--<![endif]-->也必须缩进.

使用Jade 1.0.0及更高版本,使用HTML注释是安全的,因为Jade将忽略以<字符开头的任何行.

你也可以访问这篇关于Jade IE Con​​ditional Comments的文章,其中讨论了Jade版本0.35.0和版本之间的区别1.0.0.它还显示了使用Jade mixins机制进行条件注释的替代方法.