JQuery下载和一些语法

最近学了六种jQuery选择器,我想把学过案例和知识结合起来,给大家分享下!

那么既然学jQuery选择器,肯定要先了解下jQuery是什么吧!jQuery是一个快速、简洁的JavaScript框架,相当于用jQuery能更加高效的创建JS代码,这就是jQuery,选择器是它的一种语法,代码的使用上就不能再用JS语法了,要用jQuery创建的语法。

那么用它,肯定要进行下载吧!下面附上链接和官网图片jQueryhttps://jquery.com/

1.基本选择器

这种选择器学起来简单好理解,但也很重要,因为后面的选择器是依托它的!所以这个必须学牢固

下面是基本选择器的代码:

复制代码
<html>
<head>
    <title>Title</title>
    <script src="js/jquery-3.2.1.js"></script>
    (这是调用jQuery包,只有调用后才能使用以下的jQuery语句)
</head>
<body>
    <div id="one" style="width: 500px;height: 150px;border: 1px dashed;"></div>
    <div id="two" style="width: 500px;height: 150px;border: 1px dashed;"></div>
    <div id="three" style="width: 500px;height: 150px;border: 1px dashed;"></div>
    <div class="four" style="width: 500px;height: 150px;border: 1px dashed;"></div>
    <script>
        //(以下是基本选择器)
        //id选择器
        console.log($("#one"));
        //标签名选择器
        console.log($("div"));
        //class选择器
        console.log($(".four"));
        //*选择器
        console.log($("*"));
        //联合选择器
        $(function (){
            console.log($("#one,#two,.four"));
        })
    </script>
</body>
</html>

结合代码看控制台,对应的个数分别是1、4、1、10、3,通过这些条件能进行快速、准确的查询。很方便!

复制代码
<html>
<head>
    <title>Title</title>
    <script src="js/jquery-3.2.1.js"></script>
</head>
<body>
    <div id="dv" style="width: 300px;height: 300px;border: 2px solid;">
      <input id="a" type="button" value="按钮1"/>
      <div style="width: 100px;height: 100px;border: 1px solid;padding: 10px;">
        <input id="c" type="button" value="按钮2"/>
      </div>
      <input class="b" type="button" value="按钮3"/>
      <input type="button" value="按钮4"/>
    </div>
    <button type="button" οnclick="text1()">验证后代元素选择器</button>
    <button type="button" οnclick="text2()">验证子元素选择器</button>
    <button type="button" οnclick="text3()">验证紧邻同辈元素选择器</button>
    <button type="button" οnclick="text4()">验证同辈元素选择器</button>
    <script>
    function text1(){
      console.log($("#dv input"));
    }
    function text2(){
      console.log($("#dv>input"));
    }
    function text3(){
      console.log($(".b+input"));
    }
    function text4(){
      console.log($("#a~input"));
    }
  </script>
</body>
</html>

1.选择器之间是空格的作用是验证后代元素

2.选择器之间是'>'的作用是验证子元素,就是只查看自己的儿子

3.选择器之间是'+'的作用是验证紧邻的同辈元素(不能是大哥)

4.选择器之间是'~'的作用是验证相邻的同辈元素(不能是大哥)

相关推荐
Highcharts.js4 小时前
Highcharts 云端渲染的真相:交互式图表与服务器端生成的边界
前端·信息可视化·服务器渲染·highcharts·图表渲染
zhuyan1085 小时前
Linux 系统磁盘爆满导致无法启动修复指南
前端·chrome
编程牛马姐6 小时前
独立站SEO流量增长:提高Google排名的优化方法
前端·javascript·网络
NotFound4866 小时前
实战指南如何实现Java Web 拦截机制:Filter 与 Interceptor 深度分享
java·开发语言·前端
Dontla6 小时前
高基数(High Cardinality)问题介绍(Prometheus、高基数字段、低基数字段)
前端·数据库·prometheus
whuhewei9 小时前
为什么客户端不存在跨域问题
前端·安全
妮妮喔妮9 小时前
supabase的webhook报错
开发语言·前端·javascript
qq_12084093719 小时前
Three.js 大场景分块加载实战:从全量渲染到可视集调度
开发语言·javascript·数码相机
yivifu9 小时前
手搓HTML双行夹批效果
前端·html·html双行夹注
奔跑的卡卡10 小时前
Web开发与AI融合-第一篇:Web开发与AI融合的时代序幕
前端·人工智能