2011-04-10 55 views
0


什么是将焦点置于文本字段上的最快(最快)方式?将焦点置于文本字段上的最快方式

我的页面看起来像

<html> 
<head> ... </head> 

    <body> 

    ... content ... 

    <input type="text" id="ct_one" name="ct_pet[]" value="" /> 

    ... content ... 

    <script> ... load jquery and jquery_ui ... </script> 

    </body> 

</html> 

提前感谢!
彼得

回答

2

您可以将元素之后把一个剧本,将焦点到它。这将在尽可能早的时刻确定焦点,即在元素创建之后。

<input type="text" id="ct_one" name="ct_pet[]" value="" /> 

<script type="text/javascript"> 
document.getElementById('ct_one').focus(); 
</script> 
0

将值0分配给您的输入字段的属性tabindex。

http://www.w3.org/TR/html4/interact/forms.html#adef-tabindex

+0

这只会把它放在第一个标签顺序,它不会集中它。 – Guffa 2011-04-10 09:24:59

+0

是的,我错了。它没有得到焦点,并且值“0”字段甚至不会按标签顺序排在第一位。相反,它将按照设置了“tabindex”的元素的顺序排列。我应该在发布之前检查过它。 – AlexD 2011-04-10 10:58:03