小白教程
所有教程
关于
Search
172.69.58.173
172.69.58.173
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Event blur”的源代码
本页内容
上一节:
Event_bind
下一节:
Event_change
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:blur()}}[[Category:jquery ref events|2]] = jQuery blur() 方法 = [[jquery ref events|jQuery 事件方法]] 添加函数到 blur 事件。当 <input> 字段失去焦点时发生 blur 事件: <sample title="" desc="" lang="html" hererun="1"> $("input").blur(function(){ alert("输入框失去了焦点"); }); </sample> <run name=""> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>小白教程(xiaobai.wang)</title> <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"> </script> <script> $(document).ready(function(){ $("input").blur(function(){ alert("输入框失去了焦点"); }); }); </script> </head> <body> 输入你的名字: <input type="text"> <p>在输入框写些东西,然后点击输入框外,让其失去焦点。</p> </body> </html> </run> == 定义和用法 == 当元素失去焦点时发生 blur 事件。 blur() 方法触发 blur 事件,或规定当发生 blur 事件时运行的函数。 '''提示:'''该方法常与 [[event focus|focus()]] 方法一起使用。 == 语法 == 为被选元素触发 blur 事件: $(selector).blur() <run name=""> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>小白教程(xiaobai.wang)</title> <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"> </script> <script> $(document).ready(function(){ $("#btn1").click(function(){ $("input").focus(); }); $("#btn2").click(function(){ $("input").blur(); }); }); </script> </head> <body> 输入你的名字: <input type="text"> <br><br> <button id="btn1">触发 focus 事件</button> <button id="btn2">触发 blur 事件</button> </body> </html> </run> 添加函数到 blur 事件: $(selector).blur(function) <run name=""> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>小白教程(xiaobai.wang)</title> <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"> </script> <script> $(document).ready(function(){ $("input").focus(function(){ $(this).css("background-color","#cccccc"); }); $("input").blur(function(){ $(this).css("background-color","#ffffff"); }); }); </script> </head> <body> 名字: <input type="text" name="fullname"><br> Email: <input type="text" name="email"> </body> </html> </run> {| class="table table-striped table-hover" ! 参数 ! 描述 |- | function | 可选。规定当 blur 事件发生时运行的函数。 |} [[jquery ref events|jQuery 事件方法]]
返回至“
Event blur
”。
上一节:
Event_bind
下一节:
Event_change