没有JavaScript的默认html表单焦点 [英] Default html form focus without JavaScript
问题描述
是否可以在不使用JavaScript的情况下在HTML表单上设置默认输入焦点,例如:
< html> ;
< form>
输入1:< input type =textname =textbox1/>
< br />
输入2:< input type =textname =textbox2/>
< / form>
< / html>
我不想使用JavaScript加载表单时将默认焦点设置为任一文本框(因为我希望当用户禁用js时发生这种行为)。
您可以在HTML5中执行此操作,但除此之外,您必须使用JavaScript。 HTML5允许您为表单元素添加 autofocus
,例如:
< input type =textname =myInputautofocus />
这对于支持HTML5的浏览器(或者说支持HTML5特定部分的浏览器)但如你所知,并非每个人都可以使用它。
Is it possible to set the default input focus on an HTML form without using JavaScript, for example:
<html>
<form>
Input 1: <input type="text" name="textbox1"/>
<br/>
Input 2: <input type="text" name="textbox2"/>
</form>
</html>
I want to set the default focus to either of the text-boxes when the form loads without using JavaScript (as I want the behaviour to occur when a user has js disabled).
You can do it in HTML5, but otherwise, you must use JavaScript.
HTML5 allows you to add autofocus
to your form element, eg:
<input type="text" name="myInput" autofocus />
This does work in browsers which support HTML5 (Or rather, browsers which support this particular part of HTML5) but as you know, not everybody can use it yet.
这篇关于没有JavaScript的默认html表单焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!