我已经尝试过这样做以将注意力集中在页面加载上,但它没有集中注意力
$('#profileForm :input[type=text]:first').focus();
如何在#profileForm
中的第一个控件上设置forucs更新
<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 :(得分:5)
试试这个
$('[id*=profileForm]').find('input:first').focus();
或其他选项
$('[id*=profileForm]').find('input[type=text]:visible:first').focus();
答案 1 :(得分:0)
使用以下选择器input type=text
$("#profileForm input:textarea:visible:first").focus();
对于文字区域
$("#profileForm textarea:visible:first").focus();