Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JQuery-如果用户名已填充,我希望将焦点设置在密码上_Jquery_Asp.net Mvc - Fatal编程技术网

JQuery-如果用户名已填充,我希望将焦点设置在密码上

JQuery-如果用户名已填充,我希望将焦点设置在密码上,jquery,asp.net-mvc,Jquery,Asp.net Mvc,这个函数中有一个语法错误,但我不清楚它是什么。 用户名存储在cookie上,如果存在,则由服务器检索。 当页面加载时,如果用户名没有填充,我希望关注用户名文本框。 否则,我希望它在密码文本框 <h2>Log On</h2> <p> Please enter your username and password. </p> <% using (Html.BeginForm()) { %> <%: Html.Valid

这个函数中有一个语法错误,但我不清楚它是什么。 用户名存储在cookie上,如果存在,则由服务器检索。 当页面加载时,如果用户名没有填充,我希望关注用户名文本框。 否则,我希望它在密码文本框

<h2>Log On</h2>
<p>
    Please enter your username and password.
</p>
<% using (Html.BeginForm()) { %>
    <%: Html.ValidationSummary(true, "Login was unsuccessful. Please correct the errors and try again.") %>
    <div>
        <fieldset>
            <legend>Account Information</legend>

            <div class="editor-label">
                <%: Html.LabelFor(m => m.UserName) %>
            </div>
            <div class="editor-field">
                <%: Html.TextBoxFor(m => m.UserName) %>
                <%: Html.ValidationMessageFor(m => m.UserName) %>
            </div>

            <div class="editor-label">
                <%: Html.LabelFor(m => m.Password) %>
            </div>
            <div class="editor-field">
                <%: Html.PasswordFor(m => m.Password) %>
                <%: Html.ValidationMessageFor(m => m.Password) %>
            </div>

            <div class="editor-label">
                <%: Html.CheckBoxFor(m => m.RememberMe) %>
                <%: Html.LabelFor(m => m.RememberMe) %>
            </div>

            <p>
                <input type="submit" value="Log On" />
            </p>
        </fieldset>
    </div>
<% } %>
<script type="text/javascript" language="javascript">
    $(document).ready(function () {
        if (!$.trim($("#UserName")).length) { // zero-length string AFTER a trim 
            $("#UserName").focus();
            }
        else {
            $("#Password").focus();
        } 
    }); 
</script>
移除!,试试这个

<script type="text/javascript" language="javascript">
    $(document).ready(function () {
        if ($.trim($("#UserName")).length > 0) { // zero-length string AFTER a trim 
                   $("#Password").focus(); 
            }
        else {
           $("#UserName").focus();
        } 
    }); 
</script>
移除!,试试这个

<script type="text/javascript" language="javascript">
    $(document).ready(function () {
        if ($.trim($("#UserName")).length > 0) { // zero-length string AFTER a trim 
                   $("#Password").focus(); 
            }
        else {
           $("#UserName").focus();
        } 
    }); 
</script>

我发现这确实起了作用

        // Put cursor on the first empty textbox.
        $(document).ready(function () {
            $('form input[value=]:first').focus();
        });

我发现这确实起了作用

        // Put cursor on the first empty textbox.
        $(document).ready(function () {
            $('form input[value=]:first').focus();
        });

是的!真的不应该在那里。然而,我现在发现这个解决方案在FF中有效,但在IE8中无效。我在一些模糊的javascript中发现了一个错误。请尝试使用-if$.trim$UserName.length{$Password.focus;}否则{$UserName.focus;}我没有得到有用的错误消息。我可以选择中断或继续,大量代码中突出显示了一行模糊的javascript。第二次刷新时,我看到Microsoft JScript运行时错误:对象不支持此属性或method@arame3333让我们同意吧!真的不应该在那里。然而,我现在发现这个解决方案在FF中有效,但在IE8中无效。我在一些模糊的javascript中发现了一个错误。请尝试使用-if$.trim$UserName.length{$Password.focus;}否则{$UserName.focus;}我没有得到有用的错误消息。我可以选择中断或继续,大量代码中突出显示了一行模糊的javascript。第二次刷新时,我看到Microsoft JScript运行时错误:对象不支持此属性或method@arame3333让我们