onfocus event
Examples
Implementation of a Javascript code input when the input box gets the focus:
<input type="text"
onfocus="myFunction()">
try it"
Definition and Usage
onfocus event occurs when an object receives focus.
Onfocus usually used <input>, <select>, and <a>.
Tip: Instead event onfocus event for the onblur event.
grammar
In HTML:
<element
onfocus="SomeJavaScriptCode">
In JavaScript:
object .onfocus=function(){SomeJavaScriptCode}
JavaScript, use the addEventListener () method:
object .addEventListener("focus", myScript ); 尝试一下
parameter | description |
---|---|
SomeJavaScriptCode | Required. Provisions JavaScript executed when the event occurs. |
Browser Support
All major browsers support onfocus event
It supports HTML tags onfocus event:
onfocus property is typically used for all HTML elements except: <base>, <bdo>, <br>, <head>, <html>, <iframe>, <meta>, <param>, <script>, <style> , and <title>.
Event objects