简体   繁体   中英

Focus element with HTML4.01 Strict, CSS 2.1, and JS 1.7

I am trying to figure out if there is a way to auto-focus an input element on page load that is compatible with HTML 4.01 Strict, CSS 2.1, and JS 1.7, since the autofocus attribute is not available to HTML 4.01 and I do not believe the focus method is available in JS 1.7.

Is there a way to still accomplish this with those restrictions?

I think I may have found an answer to my question. According to this w3.org document , the focus method belongs to the DOM Level 1. Does this mean that the method is indeed available?

According to this w3.org document, the focus method belongs to the DOM Level 1 so is available.

Try this code is javascript vanilla.

JAVASCRIPT

window.onload = function() {
   document.getElementById("Box1").focus();
};

HTML

<input type="text" id="Box1"/>

Anthony who was the person was asking confirm from his research. thx. Anthony Hope this help other people.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM