Javascript:根据是否IE7进行更改

dmr*_*dmr 2 javascript internet-explorer conditional-compilation internet-explorer-7

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

function showHint(myId) 
{
    document.getElementById(myId).style.display = "inline-block";
}
Run Code Online (Sandbox Code Playgroud)

对于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";
                }
            @*/
        }
Run Code Online (Sandbox Code Playgroud)

任何帮助是极大的赞赏!

编辑:我没有使用JQuery.

Jef*_*ang 7

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

<!--[if IE 7]><script> var isIE7 = true; </script><![endif]-->
Run Code Online (Sandbox Code Playgroud)