JQuery - 检测对 CSS“显示:表行组”的支持

发布于 2024-09-18 08:13:36 字数 339 浏览 2 评论 0原文

因此,Internet Explorer <= 8 不接受 CSS display 属性的标准 table-rowtable-row-group 值(除其他外)。我不愿意使用 JQuery 的 浏览器检测功能,因为这些功能已被弃用。如何在不解析浏览器/用户代理字符串的情况下检测 JQuery 中的 table-row-group 支持?也就是说,如何检测该功能的存在而不是特定浏览器的存在?

So, Internet Explorer <= 8 does not accept the standard table-row and table-row-group values for the CSS display property (amongst others). I'm reticent to use JQuery's browser detection features as these have been deprecated. How can I detect table-row-group support in JQuery without parsing the browser/user-agent string? That is, how do I detect the presence of the feature rather than the presence of a specific browser?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

所有深爱都是秘密 2024-09-25 08:13:36

我不相信使用 Javascript 可以直接检测对 CSS 属性的支持。如果这是真的,我有两个建议:

  1. 在隐藏的 div 中插入两个元素,一个带有 table-row ,一个没有。看看是否存在高度或宽度差异。如果是这样,请计算高度或宽度,并找出支持它的浏览器和不支持它的浏览器之间的差异。

  2. 即使 jQuery 的浏览器检测已被弃用,您也可以在本地托管以下脚本:

即使 tvidesign.co.uk/blog/CSS-Browser-detection-using-jQuery-instead-of-hacks.aspx" rel="nofollow noreferrer">http://www.tvidesign.co.uk/blog/CSS-Browser -detection-using-jQuery-instead-of-hacks.aspx

我使用它并且我喜欢它!它向 body 标记添加了两个类(例如“.browserIE7 和 .browserIE”),以便您可以使用 Javascript (if $('body').hasClass('browserIE7')...) 或 CSS (.browserIE7.div {...)

祝你好运!

编辑

也许可以使用Javascript...第三个选项:http ://perfectionkills.com/feature-testing-css-properties/虽然我还没有阅读这篇文章或使用他的建议。

I don't believe that with Javascript you can directly detect support for a CSS property. I have two recommendations if that's true:

  1. Insert into a hidden div two elements, one with table-row and one without. See if there's a height or width difference. If so, calculate the height or width, having figured out the difference between a browser that supports it and one that doesn't.

  2. Even though jQuery's browser detection is deprecated, you can host the following script locally:

http://www.tvidesign.co.uk/blog/CSS-Browser-detection-using-jQuery-instead-of-hacks.aspx

I use it and I love it! It adds two classes (e.g., ".browserIE7 and .browserIE") to the body tag, so that you can use Javascript (if $('body').hasClass('browserIE7')...) or CSS (.browserIE7.div {...)

Good luck!

Edit

Maybe it is possible with Javascript...3rd option: http://perfectionkills.com/feature-testing-css-properties/ although I haven't read the article or used his suggestion.

小帐篷 2024-09-25 08:13:36

如果 CSS 属性检测不起作用,我建议使用像这样的 IE 条件:

<!--[if lte IE 7]>
        <script type="text/javascript">
            var ie7 = true;
        </script>
<![endif]--> 

<!--[if lte IE 6]>
         <script type="text/javascript">
            var ie6 = true;
        </script>
<![endif]-->

或者类似的东西...也就是说,如果您想让脚本确定您使用的浏览器并且不想解析用户代理字符串。

如果您只想将 CSS 定向到特定浏览器,那么显然只需在条件中放置一个 IE 样式表的链接即可。我绝不会建议根据 JS 浏览器检测发送不同的 CSS,因为并非所有用户都会启用 JS。

If CSS property detection doesn't work out I'd recommend using IE conditionals like this:

<!--[if lte IE 7]>
        <script type="text/javascript">
            var ie7 = true;
        </script>
<![endif]--> 

<!--[if lte IE 6]>
         <script type="text/javascript">
            var ie6 = true;
        </script>
<![endif]-->

Or something along those lines...that's if you want to allow your scripts to determine which browser your using and don't want to parse the user agent string.

If you just want to direct CSS to specific browsers then obviously just put a link to an IE stylesheet in the conditionals. I would never recommend sending different CSS based on JS browser detection as not all users will have JS enabled.

[旋木] 2024-09-25 08:13:36

您可能会发现 Modernizr 很有用。它测试各种 CSS 属性,并根据这些测试将类添加到 标记中。此外,它还添加了与用户代理相关的类和其他内容。

您可以在其网站上了解有关 Modernizr 的更多信息:http://www.modernizr.com/

You might find Modernizr useful. It tests for a great variety of CSS properties, and according to these tests, adds classes to the <html> tag. Also, it adds classes relative to the user agent and that stuff.

You canr ead more about Modernizr on its site: http://www.modernizr.com/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文