IE-only JavaScript not working?

IE-only JavaScript not working?

本文关键字:working not JavaScript IE-only      更新时间:2023-09-26

我遇到了麻烦,让我的IE只加载样式表,所以我解决了一些IE只内联javascript。

但这也不起作用。有人可以看看我的代码,告诉我我做错了什么?我目前把它放在一个script标签在我的html文档的末尾,就在我的html结束标签的上方。

下面是我的代码:
<script> 
if ($.browser.msie && $.browser.version < 8) {
    // IE 7 or older
    $('.sidecolor, .EDGE-15678806, .edge-wrapper').css("display", "none");
    $('.MobileBanner').css("display", "block");
} else {
    // all other browsers
    $('.sidecolor, .EDGE-15678806, .edge-wrapper').css("display", "block");
    $('.MobileBanner').css("display", "none");
}
</script>

首先,我建议您使用这个作为一个简单的测试,您可以在script标记之间插入您的代码,一旦您看到它为您工作:

<!--[if lt IE 8]>
<script>
    alert("This is some version of IE, either 7 or below, so very not awesome!);
    /*Your code here*/
</script>
<!--[if (gte IE 8) | (!IE)]><!-->
<script>
    alert("This is some version of IE, either 8 or above, much better!);
    /*Your code here*/
</script>
<!--<![endif]-->

让我知道这是否有帮助。如果它没有,那么它可能与你的元素或你的CSS样式有关,这完全是另一个问题。

对进一步测试的参考:MSDN '关于条件注释'