html event attribute onblur triggered when an element loses focus

黄舟
Release: 2018-05-17 14:35:14
Original
8217 people have browsed it

Example

Validate the input field when the user leaves it:

<input type="text" name="fname" id="fname" onblur="upperCase()">
Copy after login

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">
Copy after login

Attribute value

ValueDescription
scriptScript 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>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template