How to create field autofocus?

I need this field to focus when the user opens the page. I don't know if it modifies anything other than inside the modal window that I am loading from a PHP file.

Is there an easy way to do this?

+3
source share
3 answers

JavaScript autofocusers (as indicated in other answers here) will work, but can be annoying for some users. For example, if you focus on another field while the page is still loading, JavaScript can “help” you by moving the focus and entering the wrong field. This question on ux.stackexchange.com lists a few more drawbacks.

, HTML5 autofocus , , , , . , . . Mark Pilgrim Dive Into HTML5.

+6

JavaScript, :

document.onload = function() {  
  document.getElementById("question-box-0").focus();
}
+6
<html>
<head>
<script>
document.onload = function() {
 document.getElementById('question-box-0').focus();
};
</script>
</head>
<body>
...
</body>
</html>
+2
source

Source: https://habr.com/ru/post/1785118/


All Articles