2012-03-03 24 views
0

第一個文本框我已經試過這樣做是爲了將焦點設置頁面加載,但它不是重點jQuery的焦點設置上頁面加載

$('#profileForm :input[type=text]:first').focus(); 

如何設置第一控制forucs在#profileForm

更新:

<div id="profileForm" runat="server" visible="true"> 
      <script language="javascript" type="text/javascript"> 
       $(document).ready(function() { 
        $('input[type=text], select, textarea').focus(function() { 
         $(this).removeClass('form-blur'); 
         $(this).addClass('form-focus'); 
        }) 

        $('input[type=text], select, textarea').blur(function() { 
         $(this).removeClass('form-focus'); 
         $(this).addClass('form-blur'); 
        }); 
        $('#profileForm input[type=text]').first().focus(); 
       }); 
      </script> 
      <table border="0" cellpadding="2" cellspacing="0" width="100%"> 
       <tr> 
        <td class="form-label" style="white-space:nowrap">First Name:</td> 
        <td> 
         <asp:TextBox ID="txtFirstName" runat="server" /></td> 
        <td rowspan="8" style="width:100%; padding-left:10px" valign="top"> 
         <asp:TextBox ID="txtSummary" runat="server" TextMode="MultiLine" Rows="4" Width="99%" /><br /> 
         Summary    
        </td> 
       </tr> 
      </table> 
     </div> 
+0

'input'是不是一個僞類 - 只刪除導致結腸和你應該很好:$('#profileForm input [type = text]')。first()。focus(); – rjz 2012-03-03 04:23:29

+0

它專注於我http://jsfiddle.net/BbSLy/1/ – DG3 2012-03-03 04:24:40

+1

你把它放在$(document).ready(){}裏面嗎? – 2012-03-03 04:25:42

回答

0

使用下面的選擇器input type=text

$("#profileForm input:textarea:visible:first").focus(); 

對於文本區域

$("#profileForm textarea:visible:first").focus(); 
5

試試這個

$('[id*=profileForm]').find('input:first').focus(); 

或其他選項

$('[id*=profileForm]').find('input[type=text]:visible:first').focus(); 
相關問題