JavaScript光標(biāo)失焦事件(onblur)
光標(biāo)失焦事件(onblur)
onblur事件與onfocus是相對事件,當(dāng)光標(biāo)離開當(dāng)前獲得聚焦對象的時候,觸發(fā)onblur事件,同時執(zhí)行被調(diào)用的程序。
下面例子,當(dāng)光標(biāo)離開時,讓用戶確認(rèn)是否已經(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("請確認(rèn)這是您的真實姓名") } </script> </head> <body> <form> 姓名: <input name="username" type="text" value="請輸入姓名" onblur="fun()" > </form> </body> </html>