
目录

1、 .on()
在选定的元素上绑定一个或多个事件处理函数
- $("#button").on("click", function(event){
- console.log("事件处理器")
- });
事件委托
- $("#ul").on("click", "li", function(event){
- console.log($(this).text());
- });
2、.one()
为元素的事件添加处理函数。处理函数在每个元素上每种事件类型
最多执行一次
- $("#btn").one("click", function() {
- console.log("这是一个只能触发一次的事件.");
- });
3、.off()
移除一个事件处理函数,移除on事件处理器
- 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>Documenttitle>
- <script src="./js/jquery-3.6.0.min.js">
- script>
- head>
- <body>
- <button id="btn1">添加事件按钮button>
- <button id="btn2">删除事件按钮button>
- <button id="btn3">按钮button>
- <script>
- function aClick() {
- console.log("点击事件")
- }
- $("#btn1").on("click",function () {
- $("#btn3").on("click", aClick);
- });
- $("#btn2").on("click",function () {
- $("#btn3").off("click", aClick);
- });
- script>
- body>
- html>
-

1、 .click()
为 JavaScript 的"click" 事件绑定一个处理器,或者触发元素上的 "click" 事件
- $("#btn").click(function() {
- alert("点击事件");
- });
2、.hover()
将二个事件函数绑定到匹配元素上,分别当鼠标指针进入和离开元素时被执行
- $("li").hover(
- // 滑入
- function () {
- console.log("滑入")
- },
- // 滑出
- function () {
- console.log("滑出")
- }
- );
3、.mouseenter()
鼠标进入事件
- $("div").mouseenter(function(){
- console.log("鼠标进入事件");
- })
4、.mouseleave()
鼠标离开事件
- $("div").mouseleave(function(){
- console.log("鼠标进入事件");
- })
5、.mousemove()
鼠标滑动事件
- $("div").mousemove(function(){
- console.log("鼠标进入事件");
- })
6、.mouseover()
鼠标进入事件(注:支持事件冒泡)
- 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>Documenttitle>
- <script src="./js/jquery-3.6.0.min.js">script>
- <style>
- .container{
- width: 200px;
- height: 200px;
- background-color: red;
- }
- .box{
- width: 100px;
- height: 100px;
- background-color: green;
- }
- style>
- head>
- <body>
- <div class="container">
- <div class="box">div>
- div>
- <script>
- $(".container").mouseover(function(){
- console.log("鼠标进入事件container");
- })
-
- $(".box").mouseover(function(){
- console.log("鼠标进入事件box");
- })
- script>
- body>
- html>
7、.mouseout()
鼠标离开事件(注:支持事件冒泡)
- 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>Documenttitle>
- <script src="./js/jquery-3.6.0.min.js">script>
- <style>
- .container{
- width: 200px;
- height: 200px;
- background-color: red;
- }
- .box{
- width: 100px;
- height: 100px;
- background-color: green;
- }
- style>
- head>
- <body>
- <div class="container">
- <div class="box">div>
- div>
- <script>
- $(".container").mouseout(function(){
- console.log("鼠标离开事件container");
- })
- $(".box").mouseout(function(){
- console.log("鼠标离开事件box");
- })
- script>
- body>
- html>

1、.focus()
为 JavaScript 的 "focus" 事件绑定一个获取焦点处理函数,或者触发元素上的 "focus" 事件
- $('#input').focus(function() {
- alert('获得焦点事件');
- });
2、.blur()
为 "blur" 事件绑定一个失去焦点处理函数
- $('#other').click(function() {
- $('#target').blur();
- });
3、.change()
为JavaScript 的 "change" 事件绑定一个表单改变处理函数
- $('.target').change(function() {
- alert('内容改变');
- });
4、.submit()
当用户提交表单时,就会在这个表单元素上触发submit事件。它只能绑定在