[英]Show Div Only in Internet Explorer (All Versions)
随着Internet Explorer删除条件语句的使用,这使我感到困惑,因为人们如何将元素或样式分别仅应用于IE。 这不再适用于IE10:
<!--[if IE]>
<![endif]-->
因此,这是一个蓝色和红色框的jsfiddle: http : //jsfiddle.net/74yK9/1/
如何使蓝色框仅出现在Internet Explorer(所有版本)中?
您可以使用jQuery来做到这一点,别忘了也包括jQuery Migrate插件 :
if ($.browser.msie) {
// For IE only
$('#bluebox').show();
} else {
// all other browsers
$('#bluebox').hide();
}
使用Javascript,可以使用仅在IE中可用的条件编译:
if (Function('/*@cc_on return true@*/')()) {
// Is IE
}
从此处进行修改: 在某些情况下,例如特定于Internet Explorer的CSS或特定于Internet Explorer的JavaScript代码,如何仅将Internet Explorer 10作为目标?
因此,使用方式类似于:
var isIE = false;
if (Function('/*@cc_on return true@*/')()) {
isIE = true;
// or
document.documentElement.className += " isIE";
}
这会在Javascript中设置一个布尔值,并且/或者还会将isIE
类添加到您的<html>
元素...这将是<html class="isIE">
。 因此,这意味着您可以检查isIE
中的boolean isIE
,也可以根据以下class
样式:
html.isIE body {
color: #111; /* Only applied for IE*/
}
这使用功能检测(种类),并且不使用userAgent
嗅探。 userAgent
嗅探是一个选项,但不可靠,在现代jQuery中已弃用/删除。
有关条件编译的更多信息: http : //www.javascriptkit.com/javatutors/conditionalcompile.shtml和http://msdn.microsoft.com/zh-cn/library/ie/121hztk3%28v=vs.94% 29.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.