JavaScript onfocus event
The JavaScript onfocus event is one of the JavaScript events . It is used to monitor an element to get the user's focus. Simply put, when the user's mouse cursor moves to the monitored field, it belongs to the focus situation. It is usually used in For textarea , input text and other form text input fields, the corresponding event is the onblur event. If you want to determine that the user enters a field, you can use onfocus event. If you want to determine that the user leaves a field, use onblur enent, all major browsers support onfocus event.
JavaScript onfocus basic syntax
onfocus = "javascript function to be triggered"
Similar to other events, onfocus is used to determine the user's behavior. When onfocus determines that the user focuses on a certain field, it will trigger a specific JavaScript function to perform the work that should be done. If the function cannot be triggered to start working, then onfocus is meaningless.
JavaScript onfocus event example
function ShowFocus(){
document.getElementById('ShowBox').innerHTML='The field has been Focus';
}
</script>
Please enter your name: <input type="text "onfocus="ShowFocus()"> <span id="ShowBox"></span>
Post a Comment
0 Comments