What does focus mean in javascript

WBOY
Release: 2022-01-28 14:37:04
Original
6485 people have browsed it

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()
Copy after login

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>
Copy after login

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!

Related labels:
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