Home > Web Front-end > JS Tutorial > js sample code to determine whether a control has focus_javascript skills

js sample code to determine whether a control has focus_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 16:57:15
Original
1130 people have browsed it

JS determines that an object has received focus document.activeElement.tagName //tagName tag name

Example: Determine whether to close the input method when the body gets the cursor.

Copy code The code is as follows:

var act = document.activeElement.tagName. toLowerCase();
if(act.indexOf("body") != -1 || act.indexOf("html") != -1)
{
document.body.style.imeMode = 'disabled';
}

<script><br>function test(){<br>var srcElem = document.activeElement<br>var testval = srcElem.name; //id and name are more commonly used and should be <br>alert("control" testval "Get focus");<br>}<br></script>



Related labels:
js
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Where is js written?
From 1970-01-01 08:00:00
0
0
0
js file code not found
From 1970-01-01 08:00:00
0
0
0
js addClass not working
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template