宝塔服务器面板,一键全能部署及管理,送你10850元礼包,点我领取

javascript中focus是什么意思-风君雪科技博客

本教程操作环境:windows10系统、javascript1.8.5版、Dell G3电脑。

javascript中focus是什么意思

focus() 方法用于为元素设置焦点(如果可以设置)。

提示:使用 blur() 方法来移除元素焦点。

语法为:

HTMLElementObject.focus()

登录后复制

示例如下:

<!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>

登录后复制

输出结果:

javascript中focus是什么意思-风君雪科技博客

相关推荐:javascript学习教程

以上就是javascript中focus是什么意思的详细内容,更多请关注风君子博客其它相关文章!