Home > Web Front-end > JS Tutorial > How to set javascript to lose focus

How to set javascript to lose focus

coldplay.xixi
Release: 2023-01-05 16:07:33
Original
8778 people have browsed it

How to set the focus of JavaScript: Use blur. The blur event type indicates a response when the element loses focus. It corresponds to the focus event type and mainly acts on form elements and hyperlink objects.

How to set javascript to lose focus

The operating environment of this tutorial: Windows 7 system, JavaScript version 1.8.5, DELL G3 computer.

Javascript loses focus setting method:

Loses focus: blur

The blur event type indicates that the element responds when it loses focus, and it is the same as the focus event The types are corresponding, mainly acting on form elements and hyperlink objects

Example: The focus and blur event handlers are bound to all input form elements, and the elements are set to appear raised when they gain focus and to appear raised when they lose focus. Sag

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<input type="text" />
<input type="text" />
<script>
var o = document.getElementsByTagName("input");
for(var i = 0; i < o.length; i++){
o[i].onfocus = function(){
this.style.borderStyle = "outset";
}
o[i].blur = function(){
this.style.borderStyle = "inset";
}
}
</script>
</body>
</html>
Copy after login

Related free learning recommendations: javascript (video)

The above is the detailed content of How to set javascript to lose 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