巨蟒python全栈开发数据库前端8:jQuery框架2

本文主要是介绍巨蟒python全栈开发数据库前端8:jQuery框架2,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

数据可视化推荐网站(都是JavaScript写的):

echart网站:

  https://echarts.baidu.com/

聚宽网站:

  https://www.joinquant.com/

我们要多用心也是可以做前端的!!!

 

回顾:

1.jquery介绍

2.jquery的引入方式

3.jquery选择器:找标签

  基本选择器:ID,Class,标签,配合使用,组合选择器,所有元素选择器,

  层级选择器:同css

  基本筛选器:选择之后进行过滤

  属性选择器:

  表单筛选器:

4.筛选器方法(将来用的会很多):下一个元素,上一个元素,父亲元素,儿子和兄弟元素,查找,筛选

5.操作标签:

  样式操作:(样式类)

  位置操作:

  尺寸:

  文本操作:

  属性操作:

  文档处理:

6.转换:jq=>dom   [0]

     dom=>jq $("this")

7.后边的django逻辑性会有很多,需要视频查漏补缺.

 

今日大纲:

1.事件

2.批量操作

3.事件冒泡

4.事件委托

 

详细内容:

1.事件

常用事件

click(function(){...})
hover(function(){...})

blur(function(){...}) focus(function(){...}) change(function(){...})
//内容发生变化,input,select等
keyup(function(){...}) mouseover 和 mouseenter的区别是:mouseover事件只要你在绑定该事件的对象上移动就会一直触发,mmouseenter事件只触发一次,表示鼠标进入这个对象

第一种绑定事件的方法: click

代码:

<!DOCTYPE html>
<html lang="zh-CN">
<head><meta http-equiv="content-Type" charset="UTF-8"><meta http-equiv="x-ua-compatible" content="IE=edge"><title>Title</title>
</head>
<body><button id="btn1">点我啊</button><!--1.button按钮--><script src="jquery-3.3.1.min.js"></script><!--2.引入js包--><script>$('#btn1').click(function () {alert('999');})//3.弹窗</script>
</body>
</html>

测试结果:点击"点我啊",弹出下面的对话框

 第二种绑定事件的方法(on):

<!DOCTYPE html>
<html lang="zh-CN">
<head><meta http-equiv="content-Type" charset="UTF-8"><meta http-equiv="x-ua-compatible" content="IE=edge"><title>Title</title>
</head>
<body><button id="btn1">点我啊</button><!--1.button按钮--><script src="jquery-3.3.1.min.js"></script><!--2.引入js包--><script>// $('#btn1').click(function () {//     alert('999');// })//3.弹窗
        $('#btn1').on('click',function () {alert('777');})//    第二种绑定事件的方法</script>
</body>
</html>

 

 测试结果:点击"点我啊",弹出下面的对话框

hover指的是,鼠标移动上去,这个事件.

 代码:测试的是hover  div标签,class值为d1

<!DOCTYPE html>
<html lang="zh-CN">
<head><meta http-equiv="content-Type" charset="UTF-8"><meta http-equiv="x-ua-compatible" content="IE=edge"><title>Title</title>
    <style>.d1{background-color: red;width: 100px;height: 100px;}</style>
</head>
<body><div class="d1"></div><button id="btn1">点我啊</button><!--1.button按钮--><script src="jquery-3.3.1.min.js"></script><!--2.引入js包--><script>// $('#btn1').click(function () {//     alert('999');// })//3.弹窗
        $('#btn1').on('click',function () {alert('777');})//    第二种绑定事件的方法
        $('.d1').hover(function () {console.log('111');})</script>
</body>
</html>

 

测试结果:鼠标每移动上去一次,下边就加一次

鼠标移动到div上,变为绿色,移动下来变成红色

<!DOCTYPE html>
<html lang="zh-CN">
<head><meta http-equiv="content-Type" charset="UTF-8"><meta http-equiv="x-ua-compatible" content="IE=edge"><title>Title</title><style>.d1{background-color: red;width: 100px;height: 100px;}</style>
</head>
<body><div class="d1"></div><button id="btn1">点我啊</button><!--1.button按钮--><script src="jquery-3.3.1.min.js"></script><!--2.引入js包--><script>// $('#btn1').click(function () {//     alert('999');// })//3.弹窗
        $('#btn1').on('click',function () {alert('777');})//    第二种绑定事件的方法
        $('.d1').hover(function () {// console.log('111');
            $(this).css('background-color','green')//    鼠标移动上去就改变为绿颜色
            },function () {$(this).css('background-color','red')//鼠标移动下来颜色颜色改变为红色
            })</script>
</body>
</html>

 focus焦点事件&blur事件:

代码案例:

<!DOCTYPE html>
<html lang="zh-CN">
<head><meta http-equiv="content-Type" charset="UTF-8"><meta http-equiv="x-ua-compatible" content="IE=edge"><title>Title</title><style>.d1{background-color: red;width: 100px;height: 100px;}</style>
</head>
<body><div class="d1"></div><input id="i1" type="text"><!--input获取焦点--><button id="btn1">点我啊</button><!--1.button按钮--><script src="jquery-3.3.1.min.js"></script><!--2.引入js包--><script>// $('#btn1').click(function () {//     alert('999');// })//3.弹窗
        $('#btn1').on('click',function () {alert('777');});//    第二种绑定事件的方法
        $('.d1').hover(function () {// console.log('111');
            $(this).css('background-color','green')//    鼠标移动上去就改变为绿颜色
            },function () {$(this).css('background-color','red')//鼠标移动下来颜色颜色改变为红色
            });$("#i1").focus(function () {$(this).css('background-color','red');//    鼠标移动到input框上去点击,变成红色
        })$("#i1").blur(function () {$(this).css('background-color','green');//    鼠标移动到input框下来点击,变成绿色
        })</script>
</body>
</html>

change事件:

html代码:选择框内发生改变,输入框的颜色发生变化

<!DOCTYPE html>
<html lang="zh-CN">
<head><meta http-equiv="content-Type" charset="UTF-8"><meta http-equiv="x-ua-compatible" content="IE=edge"><title>Title</title><style>.d1{background-color: red;width: 100px;height: 100px;}</style>
</head>
<body><div class="d1"></div><input id="i1" type="text"><!--input获取焦点--><select name="" id="s1"><option value="1">11</option><option value="2">22</option><option value="3">33</option>
</select><button id="btn1">点我啊</button><!--1.button按钮--><script src="jquery-3.3.1.min.js"></script><!--2.引入js包--><script>// $('#btn1').click(function () {//     alert('999');// })//3.弹窗
        $('#btn1').on('click',function () {alert('777');});//    第二种绑定事件的方法
        $('.d1').hover(function () {// console.log('111');
            $(this).css('background-color','green')//    鼠标移动上去就改变为绿颜色
            },function () {$(this).css('background-color','red')//鼠标移动下来颜色颜色改变为红色
            });$("#i1").focus(function () {$(this).css('background-color','red');//    鼠标移动到input框上去点击,变成红色
        });$("#i1").blur(function () {$(this).css('background-color','green');//    鼠标移动到input框下来点击,变成绿色
        });$("#s1").change(function () {$("#i1").css('background-color','blue');})</script>
</body>
</html>

keyup&keydown事件(键盘上按下来)

 //e,event代表事件

 

<!DOCTYPE html>
<html lang="zh-CN">
<head><meta http-equiv="content-Type" charset="UTF-8"><meta http-equiv="x-ua-compatible" content="IE=edge"><title>Title</title><style>.d1{background-color: red;width: 100px;height: 100px;}</style>
</head>
<body><div class="d1"></div><input id="i1" type="text"><!--input获取焦点--><select name="" id="s1"><option value="1">11</option><option value="2">22</option><option value="3">33</option>
</select><button id="btn1">点我啊</button><!--1.button按钮--><script src="jquery-3.3.1.min.js"></script><!--2.引入js包--><script>// $('#btn1').click(function () {//     alert('999');// })//3.弹窗
        $('#btn1').on('click',function () {alert('777');});//    第二种绑定事件的方法
        $('.d1').hover(function () {// console.log('111');
            $(this).css('background-color','green')//    鼠标移动上去就改变为绿颜色
            },function () {$(this).css('background-color','red')//鼠标移动下来颜色颜色改变为红色
            });$("#i1").focus(function () {$(this).css('background-color','red');//    鼠标移动到input框上去点击,变成红色
        });$("#i1").blur(function () {$(this).css('background-color','green');//    鼠标移动到input框下来点击,变成绿色
        });$("#s1").change(function () {$("#i1").css('background-color','blue');});$(window).keydown(function (e) {console.log(e.keyCode);})</script>
</body>
</html>

 

鼠标点击在页面上,再在键盘上输入字母等,显示数字,推测应该显示的是ascii码.

#shift键表示16,时刻监控着键盘,同上边一样

这个e或者event表示鼠标按下或者抬起这个事件的本身.

在键盘上按下,或者抬起

<!DOCTYPE html>
<html lang="zh-CN">
<head><meta http-equiv="content-Type" charset="UTF-8"><meta http-equiv="x-ua-compatible" content="IE=edge"><title>Title</title><style>.d1{background-color: red;width: 100px;height: 100px;}</style>
</head>
<body><div class="d1"></div><input id="i1" type="text"><!--input获取焦点--><select name="" id="s1"><option value="1">11</option><option value="2">22</option><option value="3">33</option>
</select><button id="btn1">点我啊</button><!--1.button按钮--><script src="jquery-3.3.1.min.js"></script><!--2.引入js包--><script>// $('#btn1').click(function () {//     alert('999');// })//3.弹窗
        $('#btn1').on('click',function () {alert('777');});//    第二种绑定事件的方法
        $('.d1').hover(function () {// console.log('111');
            $(this).css('background-color','green')//    鼠标移动上去就改变为绿颜色
            },function () {$(this).css('background-color','red')//鼠标移动下来颜色颜色改变为红色
            });$("#i1").focus(function () {$(this).css('background-color','red');//    鼠标移动到input框上去点击,变成红色
        });$("#i1").blur(function () {$(this).css('background-color','green');//    鼠标移动到input框下来点击,变成绿色
        });$("#s1").change(function () {$("#i1").css('background-color','blue');}); $(window).keydown(function (e) {// console.log(e.keyCode);if(e.keyCode===16){console.log('这是shift键')//    鼠标按在shift键上会显示这个
            }})</script>
</body>
</html>

mouseover表示鼠标每次从外边移动进去,则加1,

mouseenter

<!DOCTYPE html>
<html lang="zh-CN">
<head><meta http-equiv="content-Type" charset="UTF-8"><meta http-equiv="x-ua-compatible" content="IE=edge"><title>Title</title><style>.d1,#d2{background-color: red;width: 100px;height: 100px;}</style>
</head>
<body><div class="d1"></div><input id="i1" type="text"><!--input获取焦点--><select name="" id="s1"><option value="1">11</option><option value="2">22</option><option value="3">33</option>
</select>
<div id="d2"></div><button id="btn1">点我啊</button><!--1.button按钮--><script src="jquery-3.3.1.min.js"></script><!--2.引入js包--><script>// $('#btn1').click(function () {//     alert('999');// })//3.弹窗
        $('#btn1').on('click',function () {alert('777');});//    第二种绑定事件的方法
        $('.d1').hover(function () {// console.log('111');
            $(this).css('background-color','green')//    鼠标移动上去就改变为绿颜色
            },function () {$(this).css('background-color','red')//鼠标移动下来颜色颜色改变为红色
            });$("#i1").focus(function () {$(this).css('background-color','red');//    鼠标移动到input框上去点击,变成红色
        });$("#i1").blur(function () {$(this).css('background-color','green');//    鼠标移动到input框下来点击,变成绿色
        });$("#s1").change(function () {$("#i1").css('background-color','blue');});$(window).keyup(function (e) {// console.log(e.keyCode);if(e.keyCode===16){console.log('这是shift键')//    鼠标按在shift键上会显示这个
            }}); $('#d2').mouseover(function () {console.log('xxx');//    应该是在框内移动,就打印,实际情况是在每次进入才打印
        });// $('#d2').mouseenter(function () {//     console.log('xxx');//    每次进入打印一次.// });</script>
</body>
</html>

 参考菜鸟教程:(讲解有误)

 

注意:hover事件不可以通过on进行绑定.

 

事件绑定:

移除事件(不常用):

组织后续时间执行:

 

2.批量操作

当选中某个操作,按住shift,可以一起操作某个事件.

批量操作可以理解成,对一些事物,处理相同的操作的一个程序

3.事件冒泡:

事件冒泡可以理解为,触发了子事件,父事件也会跟着触发.

 代码:

<!DOCTYPE html>
<html lang="zh-CN">
<head><meta http-equiv="content-Type" charset="UTF-8"><meta http-equiv="x-ua-compatible" content="IE=edge"><title>Title</title><style>#d2{height: 100px;width:100px;background-color: green;}</style></head>
<body><div id="d1"><div id="d2"></div>
</div><script src="jquery-3.3.1.min.js"></script>
<script>$("#d1").click(function () {alert('父级标签')});$("#d2").click(function () {alert('子级标签')});
</script>
</body>
</html>

 

点击绿框:

阻止冒泡发生的方法:两种

 

<!DOCTYPE html>
<html lang="zh-CN">
<head><meta http-equiv="content-Type" charset="UTF-8"><meta http-equiv="x-ua-compatible" content="IE=edge"><title>Title</title><style>#d2{height: 100px;width:100px;background-color: green;}</style></head>
<body><div id="d1"><div id="d2"></div>
</div><script src="jquery-3.3.1.min.js"></script>
<script>$("#d1").click(function () {alert('父级标签')}); $("#d2").click(function (e) {alert('子级标签')// return false;
        e.stopPropagation()
    //下面这个方法必须加上e事件.
});
</script> </body> </html>

 

4.事件委托:

事件委托是通过事件冒泡的原理,利用父标签去捕获子标签的事件,将未来添加进来的某些子标签自动绑定上事件.

以全选,取消,反选例子为基础来进行验证事件委托.

 

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>Title</title>
</head>
<body><button id="all">全选</button>
<button id="reverse">反选</button>
<button id="cancel">取消</button>
<table border="1"><thead><tr><th>#</th><th>姓名</th><th>爱好</th></tr></thead><tbody><tr><td><input type="checkbox"></td><td>金老板</td><td>开车</td></tr><tr><td><input type="checkbox"></td><td>景女神</td><td>茶道</td></tr><tr><td><input type="checkbox"></td><td>苑昊(苑局)</td><td>不洗头、不翻车、不要脸</td></tr></tbody>
</table><!--<script src="jquery.js"></script>-->
<script src="jquery-3.3.1.min.js"></script>
<script>// 点击全选按钮 选中所有的checkbox// DOM绑定事件方法// $("#all")[0].onclick = function(){}// jQuery绑定事件方法
    $("#all").click(function () {$(":checkbox").prop('checked', true);});// 取消
    $("#cancel").on("click", function () {$(":checkbox").prop('checked', false);});// 反选
    $("#reverse").click(function () {// 1. 找到所有选中的checkbox取消选中// $("input:checked").prop('checked', false);// // 2. 找到没有选中的checkbox选中// $("input:not(:checked)").prop('checked', true);//你会发现上面这么写,不行,为什么呢?因为你做了第一步操作之后,再做第二步操作的时候,所有标签就已经全部取消选中了,所以第二步就把所有标签选中了// 方法1. for循环所有的checkbox,挨个判断原来选中就取消选中,原来没选中就选中var $checkbox = $(":checkbox");for (var i=0;i<$checkbox.length;i++){// 获取原来的选中与否的状态var status = $($checkbox[i]).prop('checked');$($checkbox[i]).prop('checked', !status);}// 方法2. 先用变量把标签原来的状态保存下来//     var $unchecked =  $("input:not(:checked)");//     var $checked = $("input:checked");//
    //     $unchecked.prop('checked', true);//     $checked.prop('checked', false);
    })</script>
</body>
</html>

 通过删除引出,委托事件:

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>Title</title><style>.shadow{position: fixed;background-color: rgba(0,0,0,0.3);top:0;left:0;bottom:0;right:0;/*设置上下左右没有距离*/z-index: 900;}.modal{position: fixed;width: 400px;height: 200px;background-color: #ffffff;top:50%;left:50%;z-index: 1000;margin-top: -100px;/*往上移动*/margin-left: -200px;/*往左移动*/}.hide{display:none;/*隐藏*/}</style>
</head>
<body><button id="all">全选</button>
<button id="reverse">反选</button>
<button id="cancel">取消</button>
<button id="add">增加</button>
<table border="1"><thead><tr><th>#</th><th>姓名</th><th>爱好</th><th>操作</th></tr></thead><tbody><tr><td><input type="checkbox"></td><td>金老板</td><td>开车</td><td><button class="b1">删除</button></td></tr><tr><td><input type="checkbox"></td><td>景女神</td><td>茶道</td><td><button class="b1">删除</button></td></tr><tr><td><input type="checkbox"></td><td>苑昊(苑局)</td><td>不洗头、不翻车、不要脸</td><td><button class="b1">删除</button></td></tr></tbody>
</table><div class="modal hide"><!--对话框开始的时候隐藏--><div><label for="name">姓名</label><input id="name" type="text"></div><div><label for="hobby">爱好</label><input id="hobby" type="text"></div><div><button class="btn2">保存</button></div>
</div><div class="shadow hide"></div>
<!--阴影层开始的时候隐藏--><!--<script src="jquery.js"></script>-->
<script src="jquery-3.3.1.min.js"></script>
<script>// 点击全选按钮 选中所有的checkbox// DOM绑定事件方法// $("#all")[0].onclick = function(){}// jQuery绑定事件方法
    $("#all").click(function () {$(":checkbox").prop('checked', true);});// 取消
    $("#cancel").on("click", function () {$(":checkbox").prop('checked', false);});// 反选
    $("#reverse").click(function () {// 1. 找到所有选中的checkbox取消选中// $("input:checked").prop('checked', false);// // 2. 找到没有选中的checkbox选中// $("input:not(:checked)").prop('checked', true);//你会发现上面这么写,不行,为什么呢?因为你做了第一步操作之后,再做第二步操作的时候,所有标签就已经全部取消选中了,所以第二步就把所有标签选中了// 方法1. for循环所有的checkbox,挨个判断原来选中就取消选中,原来没选中就选中var $checkbox = $(":checkbox");for (var i=0;i<$checkbox.length;i++){// 获取原来的选中与否的状态var status = $($checkbox[i]).prop('checked');$($checkbox[i]).prop('checked', !status);}// 方法2. 先用变量把标签原来的状态保存下来//     var $unchecked =  $("input:not(:checked)");//     var $checked = $("input:checked");//
    //     $unchecked.prop('checked', true);//     $checked.prop('checked', false);
    })//点击增加,弹出模态框
    $("#add").click(function () {// $(".modal").removeClass('hide');// $(".shadow").removeClass('hide');//整合上边的两条
        $(".modal,.shadow").removeClass('hide');})$('.btn2').click(function () {//1.获取用户输入的信息var name=$('#name').val();var hobby=$('#hobby').val();//2.创建标签,将数据添加到标签里面,拼接字符串添加标签var s="<tr>" +"<td><input type=\"checkbox\"></td>" +"<td>"+name+"</td>" +"<td>"+hobby+"</td>" +"<td><button class=\"b1\">删除</button></td>" +"</tr>";//在上边将要添加的name和hobby添加进去//3.将创建好的标签,天际到表格里面去
        $('tbody').append(s)//添加完成之后//4.关闭(隐藏)对话框
        $('.modal,.shadow').addClass('hide');//    5.清空用户输入的内容
        $('#name').val('');$('#hobby').val('');})//删除按钮事件// $('.b1').click(function () {//     $(this).parent().parent().remove();// //    通过单击button按钮,实现删除功能// })//问题:新增加的,无法绑定删除功能?应该怎么处理
//    1.将删除功能放在最后是不可行的
//    2.需要处理添加这个标签的父标签进行处理,也就是子标签委托父标签处理这个事情。//    注意由上边的.b1标签改写成tbody下的tr标签,//    给下边的tbody下的tr绑定一个click事件,click事件由button触发//    也就是把button事件的处理过程给了他的父亲.//    在这里表示把含有.b1标签的全部委托给它的父亲//
    //事件委托,将button的click事件委托给了祖父tbody标签,实现的效果就是点击button按钮,触发tbody的click事件,$(this表示的还是被点击的那个标签)//on可以做事件委托,单纯的click不可以做事件委托//参数:click事件名称,button委托人,tbody的后代标签
    $('tbody').on('click','button',function () {$(this).parent().parent().remove();})
</script>
</body>
</html>

 5.页面加载

案例1:

<!DOCTYPE html>
<html lang="zh-CN">
<head><meta http-equiv="content-Type" charset="UTF-8"><meta http-equiv="x-ua-compatible" content="IE=edge"><title>Title</title><style>.d1{background-color: red;width: 100px;height: 100px;}</style></head>
<body><div class="d1"></div>
<script src="jquery-3.3.1.min.js"></script>
<script>$('.d1').click(function () {alert('xxx');})
</script>
</body>
</html>

点击红色区域出现如下对话框.

通过window.onload实现最后加载.在头部放这个

案例:

<!DOCTYPE html>
<html lang="zh-CN">
<head><meta http-equiv="content-Type" charset="UTF-8"><meta http-equiv="x-ua-compatible" content="IE=edge"><title>Title</title><style>.d1{background-color: red;width: 100px;height: 100px;}</style><script>window.onload=function () {$('.d1').click(function () {alert('xxx');})}</script>
</head>
<body><div class="d1"></div>
<script src="jquery-3.3.1.min.js"></script></body>
</html>

缺点分析:有两个js文件也就是多人操作中,js写在html和js文件中

 html中代码:

<!DOCTYPE html>
<html lang="zh-CN">
<head><meta http-equiv="content-Type" charset="UTF-8"><meta http-equiv="x-ua-compatible" content="IE=edge"><title>Title</title><style>.d1{background-color: red;width: 100px;height: 100px;}</style><script>window.onload=function () {$('.d1').click(function () {alert('xxx');})}</script><script src="01test.js"></script>
</head>
<body><div class="d1"></div>
<script src="jquery-3.3.1.min.js"></script></body>
</html>

js代码:

window.οnlοad=function () {console.log('aaaaa');
};

 

此时只能在调试框中显示:aaaaa

 

更优化的方法:(两个都能够打印出来了)

 

html代码:

<!DOCTYPE html>
<html lang="zh-CN">
<head><meta http-equiv="content-Type" charset="UTF-8"><meta http-equiv="x-ua-compatible" content="IE=edge"><title>Title</title><style>.d1{background-color: red;width: 100px;height: 100px;}</style><script src="jquery-3.3.1.min.js"></script><script>// window.οnlοad=function () {//     $('.d1').click(function () {//     alert('xxx');// })// }
     
      //jquery页面加载完成之后做某些事情的操作 $(function () {$('.d1').click(function () {alert('xxx');})})</script><script src="01test.js"></script> </head> <body><div class="d1"></div></body> </html>

js代码(01test.js):

$(function () {console.log('aaaaa');
});

 

结果如下:

 6.动画效果

代码html:

<!DOCTYPE html>
<html lang="zh-CN">
<head><meta http-equiv="content-Type" charset="UTF-8"><meta http-equiv="x-ua-compatible" content="IE=edge"><title>Title</title><style>.d1{background-color: red;width: 100px;height: 100px;display: none;}</style>
</head>
<body><div class="d1"></div>
</body>
<script src="jquery-3.3.1.min.js"></script>
</html>

 

动画效果案例html2:

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>Title</title><style>.c1{background-color: red;/*background: url("hlw.png") no-repeat;*/width: 200px;height: 200px;/*position: absolute;*/  /*自己试以下position:absolute的效果*/display: none;}.c2{height: 100px;background-color: lawngreen;}</style>
</head>
<body><!--<div class="c1" hidden></div>-->  <!--不用hidden,上面写display:none也是可以的-->
<div class="c1"></div>
<div class="c2"></div>
<script src="jquery-3.3.1.min.js"></script>
<script>// $('.c1').hide(3000);
    $('.c1').show(3000);</script>
</body>
</html>

点赞html案例:

<!DOCTYPE html>
<html lang="zh-CN">
<head><meta charset="UTF-8"><meta http-equiv="x-ua-compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1"><title>点赞动画示例</title><style>div {position: relative;display: inline-block;}div>i {display: inline-block;color: red;position: absolute;right: -16px;top: -5px;opacity: 1;}</style>
</head>
<body><div id="d1">点赞</div>
<script src="jquery-3.2.1.min.js"></script>
<script>$("#d1").on("click", function () {var newI = document.createElement("i");newI.innerText = "+1";$(this).append(newI);$(this).children("i").animate({opacity: 0  //1秒之后透明度变为0,注意写法,animate({属性:值},毫秒数) 
    }, 1000)})
</script>
</body>
</html>

 推荐:iconfonts,阿里图标库

 7.其他

测试:

each还可以测试循环所有标签.

 html测试代码:

 

<!DOCTYPE html>
<html lang="zh-CN">
<head><meta http-equiv="content-Type" charset="UTF-8"><meta http-equiv="x-ua-compatible" content="IE=edge"><title>Title</title></head>
<body>
<ul><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li>
</ul>
<script src="jquery-3.3.1.min.js"></script>
</body>
</html>

 

测试结果:

 

 

 

代码截图 

 

 

 

 

 

 

 

8.

 标签内部也可以存储数据

 9.自定义插件

10.input事件

代码:

<!DOCTYPE html>
<html lang="zh-CN">
<head><meta http-equiv="content-Type" charset="UTF-8"><meta http-equiv="x-ua-compatible" content="IE=edge"><title>Title</title>
</head>
<body>
<input id="name" type="text">
<script src="jquery-3.3.1.min.js"></script>
<script>$('#name').on('input',function(){console.log($(this).val());})
</script>
</body>
</html>

 

 

转载于:https://www.cnblogs.com/studybrother/p/10394803.html

这篇关于巨蟒python全栈开发数据库前端8:jQuery框架2的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/756904

相关文章

Python跨文件实例化、跨文件调用及导入库示例代码

《Python跨文件实例化、跨文件调用及导入库示例代码》在Python开发过程中,经常会遇到需要在一个工程中调用另一个工程的Python文件的情况,:本文主要介绍Python跨文件实例化、跨文件调... 目录1. 核心对比表格(完整汇总)1.1 自定义模块跨文件调用汇总表1.2 第三方库使用汇总表1.3 导

基于Python实现进阶版PDF合并/拆分工具

《基于Python实现进阶版PDF合并/拆分工具》在数字化时代,PDF文件已成为日常工作和学习中不可或缺的一部分,本文将详细介绍一款简单易用的PDF工具,帮助用户轻松完成PDF文件的合并与拆分操作... 目录工具概述环境准备界面说明合并PDF文件拆分PDF文件高级技巧常见问题完整源代码总结在数字化时代,PD

Python实现Word转PDF全攻略(从入门到实战)

《Python实现Word转PDF全攻略(从入门到实战)》在数字化办公场景中,Word文档的跨平台兼容性始终是个难题,而PDF格式凭借所见即所得的特性,已成为文档分发和归档的标准格式,下面小编就来和大... 目录一、为什么需要python处理Word转PDF?二、主流转换方案对比三、五套实战方案详解方案1:

基于Python Playwright进行前端性能测试的脚本实现

《基于PythonPlaywright进行前端性能测试的脚本实现》在当今Web应用开发中,性能优化是提升用户体验的关键因素之一,本文将介绍如何使用Playwright构建一个自动化性能测试工具,希望... 目录引言工具概述整体架构核心实现解析1. 浏览器初始化2. 性能数据收集3. 资源分析4. 关键性能指

使用Python的requests库调用API接口的详细步骤

《使用Python的requests库调用API接口的详细步骤》使用Python的requests库调用API接口是开发中最常用的方式之一,它简化了HTTP请求的处理流程,以下是详细步骤和实战示例,涵... 目录一、准备工作:安装 requests 库二、基本调用流程(以 RESTful API 为例)1.

Python清空Word段落样式的三种方法

《Python清空Word段落样式的三种方法》:本文主要介绍如何用python-docx库清空Word段落样式,提供三种方法:设置为Normal样式、清除直接格式、创建新Normal样式,注意需重... 目录方法一:直接设置段落样式为"Normal"方法二:清除所有直接格式设置方法三:创建新的Normal样

Python调用LibreOffice处理自动化文档的完整指南

《Python调用LibreOffice处理自动化文档的完整指南》在数字化转型的浪潮中,文档处理自动化已成为提升效率的关键,LibreOffice作为开源办公软件的佼佼者,其命令行功能结合Python... 目录引言一、环境搭建:三步构建自动化基石1. 安装LibreOffice与python2. 验证安装

把Python列表中的元素移动到开头的三种方法

《把Python列表中的元素移动到开头的三种方法》在Python编程中,我们经常需要对列表(list)进行操作,有时,我们希望将列表中的某个元素移动到最前面,使其成为第一项,本文给大家介绍了把Pyth... 目录一、查找删除插入法1. 找到元素的索引2. 移除元素3. 插入到列表开头二、使用列表切片(Lis

Python按照24个实用大方向精选的上千种工具库汇总整理

《Python按照24个实用大方向精选的上千种工具库汇总整理》本文整理了Python生态中近千个库,涵盖数据处理、图像处理、网络开发、Web框架、人工智能、科学计算、GUI工具、测试框架、环境管理等多... 目录1、数据处理文本处理特殊文本处理html/XML 解析文件处理配置文件处理文档相关日志管理日期和

Python38个游戏开发库整理汇总

《Python38个游戏开发库整理汇总》文章介绍了多种Python游戏开发库,涵盖2D/3D游戏开发、多人游戏框架及视觉小说引擎,适合不同需求的开发者入门,强调跨平台支持与易用性,并鼓励读者交流反馈以... 目录PyGameCocos2dPySoyPyOgrepygletPanda3DBlenderFife