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
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-05-16 16:57:151111browse

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>



Statement:
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