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