如何使用 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/