jQuery_表单事件
一.方法
-
focus
为 JavaScript 的 "focus" 事件绑定一个获取焦点处理函数,或者触 发元素上的 "focus" 事件。
-
blur
为 "blur" 事件绑定一个失去焦点处理函数
-
change
为JavaScript 的 "change" 事件绑定一个表单改变处理函数
-
submit
当用户提交表单时,就会在这个表单元素上触发submit事件。它只 能绑定在 元素上
二.实例
<!DOCTYPE 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>Document</title> <script src="./jQuery/jquery-3.6.0.min.js"></script> </head> <body> <input type="text" id="username"> <form id="target"> <input type="text"> </form> <script> $('#username').focus(function() { console.log('选择焦点了!'); }) $('#username').blur(function() { console.log('失去焦点了!'); }) $('#username').change(function() { console.log('有内容被改变了!'); }); $('#target').submit(function() { alert('有数据被提交了!') }) </script> </body> </html>