我如何制作一个";否则";在IE HTML条件中

How do I make an "else" in an IE HTML conditional?

本文关键字:quot 否则 IE HTML 条件 何制作 一个      更新时间:2023-09-26
<!--[if lt IE 9]>
    This is less then IE9
ELSE
    this is all browsers: firefox, chrome, etc.
<![endif]-->

如何在HTML中做到这一点?我想做一个"其他"。。。

您不是在寻找else,而是在寻找<![if !IE]> <something or other> <!--[endif]>(请注意,这不是注释(。

<!--[if IE]>
   You're using IE!
<![endif]-->
<![if !IE]>
   You're using something else!
<![endif]>

你可以在这里找到关于条件注释的文档。

我使用以下方法在IE9或更新版本以及所有其他浏览器中加载资源

<!--[if gte IE 9]><!-->        
    //your style or script
<!--<![endif]-->

这令人难以置信。查看打开和关闭if语句部分是否在注释中(因此,它对其他浏览器不可见(,但对IE可见。

问题的解决方案是(注意<!-- -->的使用(:

<!--[if lt IE 9]>
  This is less then IE9
<![endif]-->
<!--[if gt IE 8]> <!-- -->
  this is all browsers: IE9 or higher, firefox, chrome, etc.
<!-- <![endif]-->

条件注释既可以在脚本中也可以在html-中

/*@cc_on
@if(@_jscript_version> 5.5){
    navigator.IEmod= document.documentMode? document.documentMode:
    window.XMLHttpRequest? 7: 6;
}
@else{
    alert('your '+navigator.appName+' is older than dirt.');
}
@end
@*/

您不需要执行else这是隐含的。所以

// put your other stylesheets here
<!--[if lt IE 9]>
    //put your stylesheet here for less than ie9
<![endif]-->

@cwallenpoole接受的答案会破坏标记,使HTML无效,并破坏Visual Studio的语法高亮。

以下是保持清洁的方法:

<!--[if IE]>
    You're using IE!
<![endif]-->
<!--[if !IE]><!-->
    You're not using IE. See, even SO highlights this correctly.
<!--<![endif]-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html dir="ltr" lang="en-US" xmlns="http://www.w3.org/1999/xhtml">
<head>
 <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE9">
</head>
 <!--[if IE]>
<body style="margin: 38px 0 0 0;">
 <![endif]-->
 <!--[if !IE]>
<body>
 <![endif]-->
  -Content-
 </body>
</html>

经过数小时的搜索,这对我来说很有效。我需要一个弹出横幅的头部空间,IE不想动画化。它应该在几秒钟后隐藏起来。使用这个,我可以将整个页面向下移动,但只能在IE中移动,这正是我所需要的!

目前只有那些仍然使用IE的人,我更喜欢FireFox或Chrome。

感谢您按此特定顺序提供这些字母/符号!