我有一个带有一些文本字段的表单,当页面加载时,我想将光标(自动聚焦)放在表单的第一个文本字段上。
我想不使用javascript来做。
我有一个带有一些文本字段的表单,当页面加载时,我想将光标(自动聚焦)放在表单的第一个文本字段上。
我想不使用javascript来做。
Answers:
您可以在不支持javascript的情况下进行操作。
我们可以使用html5自动对焦属性
例如:
<input type="text" name="name" autofocus="autofocus" id="xax" />
如果在文本字段中使用它(autofocus =“ autofocus”),则意味着页面加载时该文本字段将获得焦点。有关更多详细信息:http :
//www.hscripts.com/tutorials/html5/autofocus-attribute.html
<body onLoad="self.focus();document.formname.name.focus()" >
formname is <form action="xxx.php" method="POST" name="formname" >
and name is <input type="text" tabindex="1" name="name" />
it works for me, checked using IE and mozilla.
autofocus, somehow didn't work for me.
有时,您要做的就是确保光标位于文本框中:向下箭头,直到每个边缘上出现“ 0”,四个边缘(左,右,上和下)。
<input.... tabindex="1" />