相关疑难解决方法(0)

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

我一直在寻找在第n个子选择器中使用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>
Run Code Online (Sandbox Code Playgroud)

还有其他人看过这个问题吗?有办法解决这个问题吗?

css google-chrome css-selectors

12
推荐指数
2
解决办法
2万
查看次数

选择第n个孩子 - children vs childNodes属性

当你想选择第n个孩子时哪个更好或者有什么不同?请注意我不想使用jQuery.

javascript

-4
推荐指数
1
解决办法
241
查看次数

标签 统计

css ×1

css-selectors ×1

google-chrome ×1

javascript ×1