Home > Article > Web Front-end > How to set javascript to lose focus
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.
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>
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!