HTML में autofocus एट्रिब्यूट कई एलिमेंट्स के लिए उपयोग किया जाता है और पेज लोड होने पर उस विशेष एलिमेंट पर फोकस सेट करता है। जिन एलिमेंट्स में autofocus एट्रिब्यूट होते हैं वे हैं: <button>, <input>, <select> और <textarea>।
आइए अब HTML में autofocus एट्रिब्यूट को लागू करने का एक उदाहरण देखें −
उदाहरण
<!DOCTYPE html> <html> <body> <h2>परिणाम</h2> <form action="" accept-charset="ISO-8859-1"> <label for="stinfo">छात्र:</label> <input type="text" name ="stinfo"><br> <label for="sub">विषय:</label> <input type="text" name ="sub" autofocus><br> <label for="rank">रैंक:</label> <input type="number" name ="rank"><br> <label for="marks">अंक:</label> <input type="number" name ="marks"><br><br> <input type="submit"> </form> </body> </html>
आउटपुट
यह निम्नलिखित आउटपुट देगा जो दूसरे टेक्स्टबॉक्स पर फोकस प्रदर्शित करता है, क्योंकि हमने उसी इनपुट टेक्स्ट पर autofocus सेट किया है −
