首页 > 解决方案 > 在同一个视图上有两个表单,为什么我只能在第二个表单中输入文本?

问题描述

我有一个视图,它有两种形式,奇怪的是我只能在第二种形式的文本框中输入文本。

首先,div 的 ManualLogin 和 ForgotLogin 都将其不透明度设置为 0,这是在代码尝试自动验证用户身份时,ManualLogin div 的不透明度设置为 1。单击“忘记凭据”会切换 div 的不透明度ManualLogin 为 0,ForgotLogin 为 1。

就目前而言,用户名和密码文本框不能输入文本,可以输入电子邮件文本框。

如果我将 ForgotLogin div 交换到 ManualLogin div 之前,我可以在用户名和密码字段中输入文本,但不能在电子邮件字段中输入文本。

如果我将其设置为同时显示两个表单,则可以在所有框中输入文本。

是什么原因造成的,我该如何解决?

<div id="MainLoginDiv">
    <div id="LoginHeaderDiv" class="text-center">
        <h3 id="LoginHeader" class="page-header" style="color:white;">&nbsp;</h3>
    </div>
    <div id="ManualLogin" class="box" style="border: none;">
        @using (Html.BeginForm())
        {
            @Html.AntiForgeryToken()
            <div class="form-group">
                <label class="control-label" style="color:white;">Username</label>
                @Html.TextBox("username", null, new { id = "username", @class = "form-control", @Value="us" })
            </div>
            <div class="form-group">
                <label class="control-label" style="color:white;">Password</label>
                @Html.TextBox("password", null, new { id = "password", @class = "form-control", @Value = "pwd" })
            </div>
            <div class="text-center" style="margin-top:40px;">
                <input type="button" id="ManualLoginBtn" value="Sign in" class="btn btn-primary" />
                <br />
                <input type="button" id="AutoLoginBtn" value="Auto Authenticate" class="btn btn-default" />
                <input type="button" id="ForgotLoginBtn" value="Forgot Credentials" class="btn btn-default" />
            </div>
        }
    </div>
    <div id="ForgotLogin" class="box" style="border: none;">
        @using (Html.BeginForm())
        {
            @Html.AntiForgeryToken()
            <div class="form-group">
                <label class="control-label" style="color:white;">Email</label>
                @Html.TextBox("email", null, new { id = "email", @class = "form-control", @Value = "jhjhblah" })
            </div>
            <div class="text-center" style="margin-top:40px;">
                <input type="button" id="BackToLoginBtn" value="Back" class="btn btn-default" />
                <input type="button" id="ForgotSubmitBtn" value="Submit" class="btn btn-primary" />
            </div>
        }
    </div>

要切换这些 div,我只是使用 jquery 来更改 css 不透明度,例如

$("#ManualLogin").css("opacity", "0");
$("#ForgotLogin").css("opacity", "1");

标签: jqueryhtmlmodel-view-controller

解决方案


尝试使用

    $("#ManualLogin").css("display", "none");
    $("#ForgotLogin").css("display", "block");

推荐阅读