In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "how to deal with focus in javascript". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how javascript handles focus".
The methods of javascript dealing with focus are as follows: 1, to obtain focus through "field.focus ();" method; 2, to deal with losing focus through "o [I] .blur = function () {...}" method.
This article operating environment: windows7 system, javascript1.8.5 version, DELL G3 computer
How does javascript handle focus?
JavaScript focus processing (get focus focus, lose focus blur)
Focus processing
Focus processing mainly includes focus (gain focus) and blur (loss of focus) event types. The so-called focus is to activate the form field so that it can respond to keyboard events.
Get focus: focus
This event is triggered when you click or use the Tab key to switch to a form element or hyperlink object. The focus event is a way to determine the current mouse position on a page. By default, the entire document is in focus, but clicking or using the Tab key can change the focus.'
Example: after the page is loaded, shift the focus to the first text box field in the form and prepare it to receive user input
Name
Password var form = document.getElementById ("myform"); var field = form.elements ("name"); _ window.onload = function () {field.focus ();}
Losing focus: blur
The blur event type represents the response when the element loses focus, which corresponds to the focus event type and mainly acts on form elements and hyperlinked objects
Example: focus and blur event handlers are bound for all input form elements, setting protruding when the element gains focus and sunken when losing focus
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"; } }Note: if the field is hidden (
< input type="hidden" >Or use CSS's display and visibility to hide the field display, and setting its focus will throw an exception.
At this point, I believe you have a deeper understanding of "how to deal with the focus of javascript". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.