2013-01-17 52 views
7

可能重複:
How to set the focus to the first input element in an HTML form independent from the id?如何在BootStrap的第一個輸入欄中設置焦點?

我使用的自舉與ASP.NET MVC4。有一個登錄表單,但我無法專注於第一個輸入字段。

如何將焦點集中在第一個輸入字段?有沒有用於設置焦點的BootStrap類?

+0

@Richard:引導中缺少重複疑問,你已經提到過。 –

+1

此問題不是特定於引導。不管你是否使用bootstrap,解決方案都是一樣的。 – Richard

回答

24

沒有一個引導程序特定的類或函數來執行此*,但HTML5爲輸入字段提供了the autofocus attribute

This attribute currently enjoys wide browser support

* - 由於使用的是Bootsrap,並引導由jQuery的動力,你可以「墊片」舊的瀏覽器,否則不支持自動對焦:

$('[autofocus]:first').focus(); 
+0

嗯,我的答案几乎是Q/A @Richard參考答案的重複。原始內容:失敗。 –

+0

雖然共識是很好的強化。 –

+3

提示:如果您有Modernizr,您可以使用'Modernizr.input.autofocus'檢查是否需要此墊片( – user1068352

相關問題