onblur 对象失去焦点事件
生活随笔
收集整理的這篇文章主要介紹了
onblur 对象失去焦点事件
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
onblur 對象失去焦點事件
一、總結
1、幾乎所有的控件都支持onblur事件
?
二、簡介
onblur 事件
Event 對象
定義和用法
onblur 事件會在對象失去焦點時發生。
語法
οnblur="SomeJavaScriptCode"| SomeJavaScriptCode | 必需。規定該事件發生時執行的 JavaScript。 |
支持該事件的 HTML 標簽:
<a>, <acronym>, <address>, <area>, <b>, <bdo>, <big>, <blockquote>, <button>, <caption>, <cite>, <dd>, <del>, <dfn>, <div>, <dl>, <dt>, <em>, <fieldset>, <form>, <frame>, <frameset>, <h1> to <h6>, <hr>, <i>, <iframe>, <img>, <input>, <ins>, <kbd>, <label>, <legend>, <li>, <object>, <ol>, <p>, <pre>, <q>, <samp>, <select>, <small>, <span>, <strong>, <sub>, <sup>, <table>, <tbody>, <td>, <textarea>, <tfoot>, <th>, <thead>, <tr>, <tt>, <ul>, <var>支持該事件的 JavaScript 對象:
button, checkbox, fileUpload, layer, frame, password, radio, reset, submit, text, textarea, window實例 1
在本例中,我們將在用戶離開輸入框時執行 JavaScript 代碼:
<html> <head> <script type="text/javascript"> function upperCase() { var x=document.getElementById("fname").value document.getElementById("fname").value=x.toUpperCase() } </script> </head><body>輸入您的姓名: <input type="text" id="fname" onblur="upperCase()" /></body> </html>輸出:
輸入您的姓名:?
TIY
onblur參考:
onblur 事件
http://www.w3school.com.cn/jsref/event_onblur.asp
?
三、實例
驗證兩次輸入的密碼是否一致,重復輸入密碼框失去焦點的時候自動觸發
1 <tr> 2 <td>確認密碼:</td> 3 <td><input type="password" id="st4" onblur="check()"></td> 4 </tr> 5 6 <script type="text/javascript"> 7 //自定義通過ID獲取元素的函數 8 function $(id){ 9 return document.getElementById(id) 10 } 11 12 function check(){ 13 var boo=$('st3').value==$('st4').value; 14 if (boo) { 15 return true; 16 }else{ 17 alert('兩次密碼不一致') 18 } 19 20 } 21 </script>?
轉載于:https://www.cnblogs.com/Renyi-Fan/p/8973523.html
總結
以上是生活随笔為你收集整理的onblur 对象失去焦点事件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: leetcode 235. 二叉搜索树的
- 下一篇: Codeforces - 662A 思路