IE 8 和 IE 9两个版本的判定稍有不同
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>判断 IE版本</title>
<script type="text/javascript">
if(navigator.userAgent.indexOf("MSIE")>0){
if(navigator.userAgent.indexOf("MSIE 6.0")>0){
alert("ie6");
}
if(navigator.userAgent.indexOf("MSIE 7.0")>0){
alert("ie7");
}
if(navigator.userAgent.indexOf("MSIE 9.0")>0 && !window.innerWidth){
alert("ie8");
}
if(navigator.userAgent.indexOf("MSIE 9.0")>0){
alert("ie9");
}
}
</script>
</head>
<body>
</body>
</html>
其实实际环境判断IE版本的时候,还是要根据具体支持的属性、事件判断