jQuery

jQuery

JavaScript jQuery库,里面存在大量的JavaScript函数

获取jQuery

复制代码
<script>
  //原生js,选择器少,麻烦不好记
  //标签
  document.getElementsByTagName();
  //id
  document.getElementById();
  //
  document.getElementsByClassName();

  //jQuery css中的选择器它全部都能用
  $('p').click();//标签选择器
  $('#id').click();//id选择器
  $('.class').click();//class选择器
</script>
复制代码

文档工具站:https://jquery.cuishifeng.cn/

事件

鼠标事件、键盘事件、其他事件

复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="lib/jquery-3.6.0.js"></script>
    <style>
        #divMove{
            width: 500px;
            height:500px;
            border: 1px solid sandybrown;
        }
    </style>
</head>
<body>
<!--要求:获取鼠标当前的一个坐标-->
mouse: <span id="mouseMove"></span>
<div id="divMove">
在这里移动鼠标试试
</div>

<script>
    //当网页元素加载完毕之后,响应事件
    // $(document).ready(function (){});下面是简写
    $(function (){
        $('#divMove').mousemove(function (e){
            $('#mouseMove').text('x:'+e.pageX+'y:'+e.pageY);
        });
    });
</script>
</body>
</html>
复制代码

节点文本操作

$('#test-ul li[name=python]').text();//获得值
$('#test-ul li[name=python]').text('设置值');//设置值
$('#test-ul').html();//获得值
$('#test-ul').html('<strong>123</strong>');//设置值

css的操作

$('#test-ul li[name=python]').css('color','red');

元素的显示和隐藏:本质 display:none;

$(window).width();
$(window).height();
复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="lib/jquery-3.6.0.js"></script>
</head>
<body>
<ul id="test-ul">
    <li id="js">JavaScript</li>
    <li name="python">Python</li>
</ul>
<script>
// $('#test-ul li[name=python]').text('123');
</script>
</body>
</html>
复制代码

小技巧

1、如何巩固js(看jQuery源码,看游戏源码!)

2、巩固HTML、CSS(扒网站,全部down下来,然后对应修改看效果~)

posted @   少时凌云志  阅读(15)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
点击右上角即可分享
微信分享提示