"#orderedlist> li"选择器

dem*_*mas 2 jquery

我正在使用教程学习jQuery ,但其中一个示例不起作用.

<html>
  <head>
    <style type="text/css">
      a.test { font-weight: bold; background: #fc0 }
    </style>
    <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript">
      $(document).ready(function(){
        $("#ol > li").addClass("test");
        $("#some").addClass("test");
      });
    </script>
    </head>
   <body>
     <a href="http://jquery.com/" id="some">Some</a>
     <ul id="ol">
      <li>one</li>
      <li>two</li>
      <li>three</li>
    </ul>
  </body>
</html>
Run Code Online (Sandbox Code Playgroud)

此示例将"test"样式应用于超链接(#some),但不将此样式应用于有序列表(#ol).为什么?

Mar*_*ius 5

除去a

a.test { font-weight: bold; background: #fc0 }
Run Code Online (Sandbox Code Playgroud)

a将其限制为链接(锚标签).