2017-06-18 67 views
1

在WordPress中的最新版本,還有就是對網頁的用下面的代碼段:在一些IE條件註釋中額外<!-->的目的是什麼?

<!--[if lte IE 8]> 
<script type="text/javascript"> 
    document.body.className = document.body.className.replace(/(^|\s)(no-)?customize-support(?=\s|$)/, '') + ' no-customize-support'; 
</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, ' '); 

     b[c] += (window.postMessage && request ? ' ' : ' no-') + cs; 
    }()); 
</script> 
<!--<![endif]--> 

我的問題是:爲什麼說IE9的評論有一個額外的<!-->但IE8一個沒有按」 T'兩種條件有什麼區別?我有我正在調試的a PHP-based HTML Minifier腳本,我需要知道該額外片段的含義才能使解析器準確無誤。

+0

選中此項。有關詳細信息:https://msdn.microsoft.com/en-us/library/ms537512(v=vs.85).aspx –

+0

其條件註釋。 ... –

+0

@RïshïKêshKümar:我認爲基於標題可以安全地假定提問者知道什麼是條件評論。 – BoltClock

回答

1

研究如何在您的問題中突出顯示代碼。請注意,IE9部分通常會突出顯示,而不是像IE8部分那樣的巨大評論。

這是如何非IE瀏覽器以及IE9和以後看到的IE9部分。 <!-->位用於終止IE9條件註釋,以便非IE瀏覽器將會看到腳本元素以及其餘標記,並將其與IE9及更高版本一起使用,因爲它們理解並匹配條件。換句話說,<!-->位用於非IE瀏覽器以及不支持條件註釋的IE10及更高版本。 IE9及更早版本的行爲不受影響;舊版本將會像往常一樣尊重條件註釋。

沒有他們,標記看起來就像這樣:

<!--[if lte IE 8]> 
<script type="text/javascript"> 
    document.body.className = document.body.className.replace(/(^|\s)(no-)?customize-support(?=\s|$)/, '') + ' no-customize-support'; 
</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, ' '); 

     b[c] += (window.postMessage && request ? ' ' : ' no-') + cs; 
    }()); 
</script> 
<![endif]--> 

...這使得代碼無形非IE瀏覽器的整個塊,因爲它被視爲一個巨大的評論。

+0

感謝您的閃電快速反應螺栓。還有一個問題:爲什麼不直接用 - >代替?因此,條件將被<! - [if gte IE 9]> - >終止。 – terresquall

+0

@terresquall ...閱讀此...瞭解詳情:https://www.sitepoint.com/web-foundations/internet-explorer-conditional-comments/ –

+0

@terresquall:這是爲了防止IE輸出 - >作爲正常文本。 – BoltClock

相關問題