jquery 获取 如何获取div中每个第一个<p>标签, 下面这个为什么获取不到??
<html><head><scripttype="text/javascript"src="/jquery/jquery.js"></script><scripttype...
<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
$("button").click(function()
{
$(".o div p:eq(0)").css("background","red");
});
});
</script>
</head>
<body>
<div class="o">
<div>
<p>This is another paragraph.</p>
<p>This is another paragraph.</p>
</div>
<hr/>
<div>
<p>This is another paragraph.</p>
<p>This is another paragraph.</p>
</div>
</div>
<button type="button">Click me</button>
</body>
</html> 展开
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
$("button").click(function()
{
$(".o div p:eq(0)").css("background","red");
});
});
</script>
</head>
<body>
<div class="o">
<div>
<p>This is another paragraph.</p>
<p>This is another paragraph.</p>
</div>
<hr/>
<div>
<p>This is another paragraph.</p>
<p>This is another paragraph.</p>
</div>
</div>
<button type="button">Click me</button>
</body>
</html> 展开
2个回答
展开全部
把$(".o div p:eq(0)").css("background","red");改成$(".o div p:nth-child(1)").css("background","red");就可以了。
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询