html - 条件 html 语句

标签 html wordpress

我正在使用新的 wordpress 4.7 检查这个特定的语法:

<!--[if gte IE 9]><!-->
    <script type="text/javascript">
        (function() {
            var request, b = document.body, c = 'className', cs = 'customize-support', rcs = new RegExp('(^|\\s+)(no-)?'+cs+'(\\s+|$)');

                    request = true;

            b[c] = b[c].replace( rcs, ' ' );
            // The customizer requires postMessage and CORS (if the site is cross domain)
            b[c] += ( window.postMessage && request ? ' ' : ' no-' ) + cs;
        }());
    </script>
<!--<![endif]-->

我有点困惑,想知道我是否遗漏了什么。它不应该是:

<!--[if gte IE 9]>
    <script type="text/javascript">
        (function() {
            var request, b = document.body, c = 'className', cs = 'customize-support', rcs = new RegExp('(^|\\s+)(no-)?'+cs+'(\\s+|$)');

                    request = true;

            b[c] = b[c].replace( rcs, ' ' );
            // The customizer requires postMessage and CORS (if the site is cross domain)
            b[c] += ( window.postMessage && request ? ' ' : ' no-' ) + cs;
        }());
    </script>
<![endif]-->

在第一行使用空注释并在另一个注释标签中使用 endif 背后的逻辑是什么?

最佳答案

它应该对 IE8 和更低版本隐藏内容。

如果它使用您建议的第二种代码样式,那么它会在所有不支持条件注释的浏览器中隐藏内容。也就是说,它将使代码仅供 IE9 使用。

请记住,注释在 <!-- 之间延伸和 --> , 不在 <!-- 之间和 > .那里没有评论。另请参阅:添加了突出显示 Stackoverflow 的语法。

关于html - 条件 html 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41221516/

相关文章:

css - 如何让我的标题在所有媒体上响应?

html - Bootstrap Grid 设计中的行跨越

html - 忽略伪元素的边距 :before or :after

javascript - 从一个对象悬停到另一个对象,第二个 DOM 对象不会立即消失

javascript - 在 IE 7 中获取 iframe 内容

php - 在 Woocommerce 商店页面上获取产品变体图像

wordpress - 在 Buddypress 上添加自定义事件流

javascript - 在谷歌地图信息窗口中获取wordpress帖子内容

javascript - WordPress - 无法在页面中找到 JS 代码片段

html - 将滚动条放在 div 标签的末尾