在html中,焦點是光標(biāo)的意思,元素通過鼠標(biāo)點擊就可以獲得光標(biāo),也即獲得焦點;可以利用autofocus屬性來規(guī)定當(dāng)頁面加載時元素會自動獲得焦點,該屬性是一個布爾屬性,若指定元素設(shè)置該屬性則會獲得焦點,語法為“<指定元素 autofocus="autofocus">”。
本教程操作環(huán)境:windows10系統(tǒng)、HTML5版本、Dell G3電腦。
html焦點是什么意思
焦點在HTML和JS中是指光標(biāo)。
焦點在JS和HTML里是在頁面上屏幕中閃動的小豎線,鼠標(biāo)點擊就可獲得光標(biāo),Tab鍵可按照設(shè)置的Tabindex來進行切換焦點。
autofocus 屬性規(guī)定當(dāng)頁面加載時 input 元素應(yīng)該自動獲得焦點。
如果使用該屬性,則 input 元素會獲得焦點。
autofocus 屬性是 HTML5 中的新屬性。
autofocus 屬性是一個布爾屬性。
autofocus 屬性規(guī)定當(dāng)頁面加載時 <input> 元素應(yīng)該自動獲得焦點。
語法如下:
<input autofocus>
或者
<input autofocus="autofocus">
示例如下:
<form action="demo_form.asp"> First name: <input type="text" name="fname" autofocus><br> Last name: <input type="text" name="lname"><br> <input type="submit"> </form>
輸出結(jié)果:
一旦刷新頁面就會獲得焦點
(學(xué)習(xí)視頻分享:css視頻教程、html視頻教程)