JavaScript光標失焦事件(onblur)
光標失焦事件(onblur)
onblur事件與onfocus是相對事件,當光標離開當前獲得聚焦對象的時候,觸發(fā)onblur事件,同時執(zhí)行被調用的程序。
下面例子,當光標離開時,讓用戶確認是否已經(jīng)輸入信息:
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>php.cn</title> <script> function fun(){ window.alert("請確認這是您的真實姓名") } </script> </head> <body> <form> 姓名: <input name="username" type="text" value="請輸入姓名" onblur="fun()" > </form> </body> </html>