jQuery将重点放在页面加载的第一个文本框上 [英] jquery set focus on first textbox on pageload

查看:94
本文介绍了jQuery将重点放在页面加载的第一个文本框上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图这样做以将注意力集中在页面加载上,但它没有聚焦

i've tried doing this to set focus on pageload but it's not focusing

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

我如何在#profileForm中的第一个控件上设置forucs

how can i set forucs on the first control in #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>

推荐答案

尝试一下

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

或其他选项

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

这篇关于jQuery将重点放在页面加载的第一个文本框上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆