2013-12-09 33 views
-1

我想重點放在加載頁面後的表單的第一個輸入,但它不工作!在Jquery中加載頁面後設置焦點?

$("#New").click(function() { 
    var area = $(this).attr("name");  
    $("#txtHint").hide().load("add_data.php?area=" + area, function(){ 
     $(this).closest("form").find(':input:enabled:visible:first').focus(); 
    }).fadeIn('slow'); 
    //$(this).closest("form").find(':input:enabled:visible:first').focus(); 
}); 

我可以幫忙嗎?

+0

的語法高亮上面,你可以看到你沒有正確關閉雙引號。 –

+0

修復語法錯誤並重試:'$(「#txtHint」)。hide()。load(「add_data.php?area =」+ area,function(){...}); ' –

+1

@scrowler另外[選擇器](http://api.jquery.com/input-selector/) – George

回答

0

你的代碼改寫爲

$("#txtHint").hide().load("add_data.php?area=" + area, function(){ 
2

假設你有這樣的代碼:

<form id="formId"> 
<input type="text"> 
<input type="text"> 
<input type="text"> 
</form> 

寫這個jQuery代碼:

$("#formId input:text").first().focus(); 

包裹着

$(document).ready(); 
+0

我希望焦點是點擊按鈕 –

+0

簡單地$(「#button」)。click(function(){$(「#formId input:text」)。first()。focus();}); –

+0

如果你看到這樣的問題:我試圖在加載頁面 –

0

嘗試:

$(document).ready(function(){ 
    $("#inputId").focus(); 
}); 
相關問題