gpt4 book ai didi

css - 在 Chrome 中嵌套 nth-child 的 querySelector 似乎不起作用

转载 作者:技术小花猫 更新时间:2023-10-29 10:36:34 24 4
gpt4 key购买 nike

我一直在考虑在 nth-child 选择器中使用 nth-child 来查找元素。这似乎适用于 Firefox,但似乎不适用于 chrome。这是我的测试文件:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>untitled</title>
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->

<script type="text/javascript" charset="utf-8">
myFunc = function() {
if(document.querySelector('#wonderful DIV:nth-child(2) DIV:nth-child(2)')) {
alert("found the element");
} else {
alert("element not found");
}
};
</script>
</head>
<body onLoad="myFunc()">

<div id="wonderful">
<div>
</div>
<div >
<div>
</div>
<div class="blue">
find me!
</div>
</div>
</div>

</body>
</html>

还有其他人看到过这个问题吗?有解决这个问题的解决方案吗?

最佳答案

这在 chrome 中对我有用,但在 FF 中不起作用。

document.querySelector('#wonderful div:nth-child(2):nth-child(2)')

以下片段适用于两种浏览器,但我假设您已经知道了

document.querySelector('#wonderful div:nth-child(2) div.blue')

所以对我来说,这看起来像是 chrome 中的实现失败。

关于css - 在 Chrome 中嵌套 nth-child 的 querySelector 似乎不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6345358/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com