JQuery

JQuery的三种写法

1、完整写法

    $(document).ready(function() {

            })

2、简写(1)

 $().ready(function() {

            })

3.常用

   $(function() {

        })

二、认识JQuery

使用jquery实现一个小案例:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 引入jQuery -->
    <script src="../js/jquery-3.6.0.min.js"></script>
    <style>
        div {
            width: 200px;
            height: 200px;
            background-color: red;
            margin-bottom: 10px;
            margin-top: 10px;
            display: none;
        }
    </style>
</head>

<body>
    <input type="button" id="click" value="显示">
    <div id="div1"></div>
    <div id="div2"></div>
</body>
<script>
    $(function() {
        $("#click").click(function() {
            // $("div").css("display", "block")
            $("div").show(2000)
        })
    })
</script>

</html>

效果:

 三、选择器

  • id:根据 id 查找标签对象
  • class 选择器:根据 class 查找标签对象

  • 标签选择器:选择器:根据标签名查找标签对象

  • * 选择器:表示任意的,所有的元素

层次选择器

  •  后代选择器 :在给定的祖先元素下匹配所有的后代元素,即包括儿子元素,也包括孙子等其他元素

  •  子元素选择器:在给定的父元素下匹配所有的子元素,只包括儿子元素,不包括孙子等其他元素

ID选择器(使用#名称)

案例(计算两个数、点击变颜色)

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../js/jquery-3.6.0.min.js"></script>
    <style>
        .div0 {
            width: 200px;
            height: 200px;
            margin-bottom: 30px;
            background-color: aqua;
        }
    </style>
</head>

<body>
    <input type="text" id="one">+
    <input type="text" id="tow">=
    <input type="text" id="result" disabled>
    <input type="button" value="计算" id="click">
    <hr>
    <input type="button" name="" id="gai" value="更改">
    <div class="div0">这是一个div</div>
    <p class="div0">这是一个p</p>
</body>
<script>
    $(function() {
        //计算
        // 获取按钮绑定单击事件
        $("#click").click(function() {
                //获取input输入的值  val():如果不传参数就是获取到value值,要是传参就是更改值
                var on =
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值