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

WBOY
Release: 2016-05-16 16:57:15
Original
1083 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
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template