Example
Validate the input field when the user leaves it:
<input type="text" name="fname" id="fname" onblur="upperCase()">
Browser support
IE
Firefox
Chrome
Safari
Opera
All major browsers support onblur attribute.
Definition and Usage
The onblur attribute is triggered when the element loses focus.
onblur is often used in form validation code (such as the user leaving a form field).
Tip: The onblur attribute is the opposite of the onfocus attribute.
Differences between HTML 4.01 and HTML5
None.
Syntax
<element onblur="script">
Attribute value
Value | Description |
script | Script to run when onblur occurs. |
Example:
<!-- ------------------------------ --> <!-- 文件范例:15-20.htm --> <!-- 文件说明:OnBlur事件 --> <!-- onblur 是控件在失去焦点的时候触发的事件 --> <!-- ------------------------------ --> <html> <head> <title>OnBlur事件</title> </head> <body> <Form> <input type="text" name="test1" value="test1"> <input type="text" name="test2" value="test2" onBlur=alert("我失去了输入焦点!")> </Form> </body> </html>
The above is the detailed content of html event attribute onblur triggered when an element loses focus. For more information, please follow other related articles on the PHP Chinese website!