ユーザがそこを離れたときに入力フィールドを検証します:
<input type="text" name="fname" id="fname" onblur="myFunction()">
Try it Yourself ❯
他の "Try it Yourself" の例が下にあります。
onblur 属性は、要素がフォーカスを失った瞬間に発火します。
Onblur は、ほとんどの場合、(例えば、ユーザがフォームフィールドを離れる時に)フォームのコード検証に使用されます。
チップ: onblur attribute is the opposite of the onfocus attribute.
イベント属性 | |||||
---|---|---|---|---|---|
onblur | Yes | Yes | Yes | Yes | Yes |
なし。
<element onblur="script">
値 | 説明 |
---|---|
script | script は onblur で実行される |
サポートする HTML タグ: | 次の要素を除くすべての HTML 要素: <base>, <bdo>, <br>, <head>, <html>, <iframe>, <meta>, <param>, <script>, <style>, and <title> |
---|
"onblur" と一緒に "onfocus" 属性を使用します:/p>
<input type="text" onfocus="focusFunction()" onblur="blurFunction()">
Try it Yourself ❯
HTML DOM リファレンス:onblur イベント