如何在jade中添加一个HTML标签?

在翡翠 ,我想要放在一个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]--> 

在一个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 ... 

但是jade忽略了html标签,并且不会在最后写</html>标签。 这是无效的HTML,并导致IE不显示任何东西。

有什么办法吗?

我想我会只使用一个JavaScript解决scheme,如果没有办法。

这个方法的工作,closuresHTML标签:

 !!! 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 

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

更新:

正如kumar-harsh所指出的那样,这个行为现在已经被折旧了,如果你需要这个function,你现在应该使用普通的html:

 <!--[if IE]> <html class="ie"> <![endif]--> <![if !IE]> <html class="not-ie"> <![endif]> </html> 

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

这就是你正在寻找的,它也会给结束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 

简单地使用这个语法,介意不同的缩进:

 !!! 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 … 

1.0.0版(2013年12月22日发布)中,Jade不再parsing评论内容,IE条件注释的支持已被删除( //if lt IE 7不能在0.35.0及更低版本中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]--> ... 

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

使用Jade版本1.0.0及以上版本时,使用HTML注释是安全的,因为Jade会忽略任何以<字符开头的行。

您也可以在IE浏览器中的条件注释(IE Con​​ditional Comments in Jade)上访问这篇文章 ,其中讨论了Jade版本0.35.01.0.0之间的区别。 它还展示了使用Jade mixin机制进行条件注释的替代方法。

从版本1.0.0开始, // if构造不再神奇了 。 或者按照原文呈现HTML(任何以<开始的行由Jade原样传输),或者使用一个mixin,如Tom的博客引用另一个答案:

 mixin ie(condition) | <!--[!{condition}]> block | <![endif]--> doctype html html head title= My title +ie('if IE 8') link(rel='stylesheet', href='/stylesheets/style-ie8-1.css') 

很简单。

例:

HTML

 <!--[if lt IE 7 ]><html class="ie ie6" lang="en"><![endif]--> <!--[if IE 7 ]><html class="ie ie7" lang="en"><![endif]--> <!--[if IE 8 ]><html class="ie ie8" lang="en"> <![endif]--> 

 //[if lt IE 7]> <html class="ie ie6" lang="en"> <![endif] //[if IE 7]> <html class="ie ie7" lang="en"> <![endif] //[if IE 8]> <html class="ie ie8" lang="en"> <![endif] 

据我所知你不能把这样的html标签放在玉石里。 对于这个要么你需要包括一个HTML或通过使用尾随(。)标签支持文本如:

 p. <html><script></script>.... 

所以HTML标签不支持文本,所以你不能这样做。 另一个解决scheme是:

 -if IE==6 html.ie6 -if IE==7 html.ie7 -if IE==8 html.ie8 -if IE==9 html.ie9 head body h1 My sit