javascript中focus是什么意思
生活随笔
收集整理的這篇文章主要介紹了
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學習教程
以上就是javascript中focus是什么意思的詳細內容,更多請關注風君子博客其它相關文章!
總結
以上是生活随笔為你收集整理的javascript中focus是什么意思的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: supervisor进程管理工具
- 下一篇: 6s plus尺寸