HTML select tag attribute similar to autofocus

2019-09-11 03:19发布

Is there any attribute for select tag in HTML like autoFocus for textbox ? So that select should have default focused. Means I want to do autofocus for select tag.

标签: html html5
1条回答
We Are One
2楼-- · 2019-09-11 04:06

You can use autofocus in the select tag as follows:

<select autofocus>
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="mercedes">Mercedes</option>
  <option value="audi">Audi</option>
</select>

If you run the code snippet and then immediately press enter or the down arrow then you will see that the select has the focus on the page. Is this what you wanted?

查看更多
登录 后发表回答