Home  >  Article  >  Web Front-end  >  What does focus mean in javascript

What does focus mean in javascript

WBOY
WBOYOriginal
2022-01-28 14:37:046465browse

In JavaScript, focus means "focus". The focus() method can be used to set focus for an element, and the syntax is "HTMLElementObject.focus()".

What does focus mean in javascript

The operating environment of this tutorial: Windows 10 system, JavaScript version 1.8.5, Dell G3 computer.

What does focus mean in javascript

The focus() method is used to set focus for an element (if it can be set).

Tip: Use the blur() method to remove element focus.

The syntax is:

HTMLElementObject.focus()

The example is as follows:

<!DOCTYPE html>
<html>
<head>
<style>
a:focus, a:active {
    color: green;
}
</style>
</head>
<body>

<a id="myAnchor" href="//www.php.cn">获取焦点</a>

<p>点击按钮设置或移除以上链接的焦点。</p>

<input type="button" onclick="getfocus()" value="获取焦点">
<input type="button" onclick="losefocus()" value="移除焦点">

<script>
function getfocus() {
    document.getElementById("myAnchor").focus();
}

function losefocus() {
    document.getElementById("myAnchor").blur();
}
</script>

</body>
</html>

Output result:

What does focus mean in javascript

Related recommendations: javascript learning tutorial

The above is the detailed content of What does focus mean in javascript. For more information, please follow other related articles on the PHP Chinese website!

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