Home > Web Front-end > HTML Tutorial > html event attribute onfocus that is triggered when an element gains focus

html event attribute onfocus that is triggered when an element gains focus

黄舟
Release: 2017-11-04 11:39:04
Original
5251 people have browsed it

Example

Execute a JavaScript when an input field gets focus:

<input type="text" id="fname" onfocus="setStyle(this.id)">
Copy after login

Browser support

##IE

Firefox

Chrome

Safari

Opera

##All major browsers support the onfocus attribute.

Definition and Usage

The onfocus attribute is triggered when an element receives focus.

onfocus is commonly used in ,