jQuery基础知识1

本文详细介绍了jQuery的基础概念,包括库的下载与引用方法,如何使用入口函数进行DOM操作、事件处理及样式调整。通过实例演示了动画效果的实现,如淡入淡出、滑动等,展示了jQuery简化JavaScript编程的强大功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

jquery的概念

  js query

  jquery库

  封装了大量js,封装js的入口函数、兼容性问题、DOM操作、事件、ajax

使用jquery

  下载包

  引用

  <script src="jquery.js"></script>

<script>
            //入口函数
            $(function(){
            
                //DOM操作三步走:事件源 事件 事件驱动 
                
                //选择器 就是来获取事件源的
                id
                    $('#box')
                class
                    $('.box')
                标签
                    $('div')
                    
                //事件和事件驱动 在click方法中的函数称为回调函数
                
                $('#box').click(function(){
                    //对样式的操作
                    .css()方法
                    
                
                })
                    
                
            
            });
        </script>

jquery的文件讲解

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .wrap{
            width: 100px;
            height: 100px;
            background-color: green;
        }
    </style>
</head>
<body>
    <div id="box" class="wrap">qing</div>
    <!--1导入模块,在前端中一个js文件是模块,一个css也可以是一个模块,一个html/png/mp3-->
    <script type="text/javascript" src="./jquery.js"></script>

    <script>
        //jquery内部的aip 99%都是方法
        console.log(jQuery)
        console.log($("#box"))
        //三步走
        $("#box").click(function () {
            //千万不要用js的属性和方法 js调用js的属性和方法 jquery对象调用的是jquery的对象和方法
            $(".wrap").css(
                {
                    "backgroundColor" :"yellow",
                    width:"300px"
                }
            )
        })
    </script>
</body>
</html>
View Code

jquery的入口函数

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="jquery.js"></script>
</head>
<body>
    <div id="box">

    </div>
    <script>
        //1.入口函数 不用等待图片资源加载完成之后就可以调用 它没有事件覆盖现象
        // $(document).ready(function () {
        //     //回调函数
        //     console.log($("#box"))
        // })

        $(function () {
            console.log($("box"))
        });
        $(function () {

        });
    </script>
</body>
</html>
View Code

jquery的动画

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        #box{
            width: 200px;
            height: 200px;
            background-color: red;
            /*display: none;*/
        }
    </style>
</head>
<body>
    <button>动画</button>
    <button>动画</button>
    <button>动画</button>
    <button>动画</button>
    <button>动画</button>
    <button>动画</button>
    <div id="box"></div>
    <script src="jquery.js"></script>
    <script>
        $(function () {
            console.log($("button"));
            var isShow = true;
            $("button").click(function () {
                //隐藏,显示  第二个元素是隐藏或显示后执行的函数
                // $("#box").hide(2000);
                // $("#box").show(2000,function () {
                //     alert(22222);
                // })
                //显示  淡入淡出
                // $("#box").fadeIn(5000);
                // $("#box").fadeOut(5000);
                if(isShow){
                    $("#box").stop().slideUp(1000);
                    isShow = false;
                }else {
                    $("#box").stop().slideDown(1000);
                    isShow = true;
                }

            })
        })
    </script>
</body>
</html>
View Code

 

转载于:https://www.cnblogs.com/qq849784670/p/9720386.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值