jQuery点击事件

点击DIV,修改第二个p元素的背景色为"orange"

先看看效果:
在这里插入图片描述这种点击修改什么内容,颜色,原理都是一个套路

代码的展示:

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <script src="jquery.js"></script>
    <style>
        div{
            width: 200px;
            height: 200px;
            background-color: bisque;
        }
    </style>
</head>
<body>
<center>

<h2>点击DIV,修改第二个p元素的背景色为"orange"</h2>
<div>
<p>我是第一个元素</p>
<p>我是第二个元素</p>
<p>我是第三个元素</p>
</div>
</center>
<script>
    $(function () {
        $("div").on("click",function () {
            $("div p:first-child").next().css("background-color","orange")
        })
    })
</script>

</body>
</html>
发布了27 篇原创文章 · 获赞 45 · 访问量 2670

猜你喜欢

转载自blog.csdn.net/weixin_45746635/article/details/102766537