对于某些情况,如 Internet Explorer 特定的 CSS 或 Internet Explorer 特定的 JavaScript 代码,如何仅针对 Internet Explorer 10?

对于某些情况,如 Internet Explorer 特定的 CSS 或 Internet Explorer 特定的 JavaScript 代码,我如何仅针对 Internet Explorer 10?

How do I target only Internet Explorer 10 for certain situations like Internet Explorer-specific CSS or Internet Explorer-specific JavaScript code?

我试过了,但它不起作用:

I tried this, but it doesn't work:

<!--[if IE 10]>    <html class="no-js ie10" lang="en"> <![endif]-->
<!--[if !IE]><!--> <html lang="en" class="no-js"> <!--<![endif]-->

Internet Explorer 10 忽略条件注释并使用 <html lang="en" class="no-js"> 代替 <html class="no-js ie10" lang="en">.

Internet Explorer 10 ignores the conditional comments and uses the <html lang="en" class="no-js"> instead of <html class="no-js ie10" lang="en">.

推荐答案

或许你可以试试这样的jQuery:

Perhaps you can try some jQuery like this:

if ($.browser.msie && $.browser.version === 10) {
  $("html").addClass("ie10");
}

要使用此方法,您必须包含 jQuery Migrate 库,因为此函数已从主 jQuery 库中删除.

To use this method you must include the jQuery Migrate library because this function was removed from the main jQuery library.

对我来说效果很好.但肯定不能替代条件注释!

Worked out quite fine for me. But surely no replacement for conditional comments!

相关文章