我正在学习 jQuery this教程,但其中一个示例不起作用。
<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>
此示例将“test”样式应用于超链接 (#some),但不将此样式应用于有序列表 (#ol)。为什么?
最佳答案
从
中删除a
a.test { font-weight: bold; background: #fc0 }
a 将其限制为链接( anchor 标记)。
关于jquery - "#orderedlist > li"选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1895876/