2

我想根据浏览器是否为 IE7 更改我的 javascript 代码行。以下是任何其他浏览器的代码:

function showHint(myId) 
{
    document.getElementById(myId).style.display = "inline-block";
}

对于 IE7,我想要 display = "inline"。

我尝试过条件编译(向我展示了如何检测浏览器),但它没有用:

function showHint(myId) 
        {
            document.getElementById(myId).style.display = "inline-block";
            /*@cc_on
                @if(navigator.appVersion.indexOf(“MSIE 7.”)!=-1)
                {
                    document.getElementById(myId).style.display = "inline";
                }
            @*/
        }

任何帮助是极大的赞赏!

编辑:我没有使用 JQuery。

4

5 回答 5

7

设置一个由 IE 的条件注释解析行为决定的全局:

<!--[if IE 7]><script> var isIE7 = true; </script><![endif]-->
于 2010-05-26T19:51:51.447 回答
2

你需要检查navigator.userAgent

如果你使用 jQuery,你可以简单地写

if ($.browser.msie && $.browser.version === 7)
于 2010-05-26T19:51:43.827 回答
1

我认为您可以使用正则表达式来确定 MSIE 7:

if(/MSIE 7/.test(navigator.appVersion)) { /* msie7 related code */ }
于 2010-05-26T19:54:56.893 回答
0

有一个检测浏览器版本的 Jquery 插件。我不知道确切的链接...

于 2010-05-26T19:51:05.747 回答
0
于 2010-05-26T20:09:36.330 回答