2012-03-03 80 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();