Give focus to an element:
document.getElementById("myAnchor").focus();
Try it Yourself »
Give focus to a text field:
document.getElementById("myText").focus();
Try it Yourself »
Give focus to a text field when the document has been loaded:
window.onload = function() {
document.getElementById("myText").focus();
}
Try it Yourself »
The focus()
method gives focus to an element (if it can be focused).
element.focus()
NONE |
NONE |
element.focus()
is a DOM Level 2 (2001) feature.
It is fully supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | 9-11 |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!