javascript - 检测到 :first-child support

标签 javascript jquery css css-selectors

如何使用 JavaScript 检测浏览器是否支持 CSS :first-child 选择器?

最佳答案

你可以只使用 :first-child 规则来设置一些特定的值,然后在 Javascript 中获取计算样式以查看 :first-child 规则是否被应用,例如

<style>
#foo { width: 200px; }
#foo:first-child { width: 400px; }
</style>

<span><span id="foo"></span></span>

<script>
if ($('#foo').width() < 400)
   alert('first-child not supported.');
</script>

(这没有经过测试。我没有 IE 6。)

关于javascript - 检测到 :first-child support,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3692450/

相关文章:

javascript - 在单页应用程序上重用 Google Maps API 实例

php - 如何从 ePub 图书写入服务器

javascript - 从 url 中删除 # 字符

css - 样式表已链接但未加载?

html - IE背景图片不显示

javascript - 如何将带有键作为索引的对象转换为 JavaScript 中的数组?

javascript - 与 Node 异步不是更好吗

php - 在 MYSQL 语句中连接 PHP 变量 DATETIME

javascript - DataTables 个别列搜索框与 colvis 冲突

html - 图片未超链接