2010-09-16 83 views

回答

4

您可以使用:input:first選擇與.focus(),像這樣:

$(function() { 
    $(':input:first').focus(); 
}); 

或者因爲你說的母版頁,你可以有一定的內容區域或東西,所以只是前綴上選擇,例如:

$('#content :input:first').focus(); 

:input選擇器選擇所有輸入,文本區域,選擇和按鈕元素,所以它會搶先輸入的任何<form>

+0

你搖滾,craver;) – mare 2010-09-16 10:19:48

+0

@mare - 只是想幫助:) – 2010-09-16 10:20:38

1
$(document).ready(function() { 
    $('input').first().focus(); 
}); 
0

這將焦點聚集到第一的TextInput/textarea的頁面

$(function(){ 
    $('input[type=text], textarea').first().focus(); 
}) 
2

這裏僅選取可見並啓用投入做的更簡單的方式上。

$(function() { 
    $(':input:visible:enabled:first').focus(); 
}); 
+0

不錯,謝謝你 – mare 2010-09-16 16:52:06

相關問題