使用js打开模态对话框

本文关键字:模态 对话框 js 使用 | 更新日期: 2023-09-27 18:12:40

我有以下模态对话框(弹出)使用只有CSS3在我的asp页面的用户注册:HTML:

<%-- Modal PopUp starts here--%>
    <div id="openModal" class="modalDialog">
        <div>   <a href="#close" title="Close" class="close" onclick="DisableAllPopUpTxt()">X</a>
            <table style="width:100%;">
                <tr>
                    <td style="text-align: center; width: 100%;"></td>
                </tr>
                <tr>
                    <td style="text-align: center; width: 100%;">
                        <asp:Label ID="lblErrorMSG2" runat="server" Font-Bold="True" ForeColor="#FF3300" Text="Email ID Already Taken " Visible="False"></asp:Label>
                    </td>
                </tr>
                <tr>
                    <td style="text-align: center; width: 100%;">
                        <input id="txtCustFName" name="txtCustFName" type="text" required placeholder="Enter Your First Name" style="width: 80%" />
                    </td>
                    </td>
                </tr>
                <tr>
                    <td style="text-align: center; width: 100%;">
                        <input id="txtCustLName" name="txtCustLName" type="text" required placeholder="Enter Your Last Name" style="width: 80%" />
                    </td>
                    </td>
                </tr>
                <tr>
                    <td style="text-align: center; width: 100%;">
                        <input id="txtCustREmail" name="txtCustREmail" type="email" required placeholder="Enter Valid Email ID" style="width: 80%" />
                    </td>
                    </td>
                </tr>
                <tr>
                    <td style="text-align: center; width: 100%;">
                        <input id="txtCustRPwd" name="txtCustRPwd" type="password" required placeholder="Enter Password" style="width: 80%" />
                    </td>
                    </td>
                </tr>
                <tr>
                    <td style="text-align: center; width: 100%;">
                        <input id="txtCustRePwd" name="txtCustRePwd" type="password" required placeholder="ReType Password" style="width: 80%" />
                    </td>
                    </td>
                </tr>
                <tr>
                    <td style="text-align: center; width: 100%;">
                        <input id="txtCustPh" name="txtCustPh" type="number" size="10" min="10" max="10" required placeholder="Enter Valid Mobile No" style="width: 80%" />
                    </td>
                    </td>
                </tr>
                <tr>
                    <td class="style1" style="text-align: center; width: 100%;" onclick="btnSignUp()">
                        <asp:Button ID="btnSingUp" runat="server" onclick="signUp" Text="Login" />
                    </td>
                </tr>
                <tr>
                    <td style="text-align: center; width: 100%;">&nbsp;</td>
                </tr>
            </table>
        </div>
    </div>
    <%--Modal PopUp Ends Here--%>
CSS:

.modalDialog {
        position: fixed;
        font-family: Arial, Helvetica, sans-serif;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        background: rgba(0,0,0,0.8);
        z-index: 99999;
        opacity:0;
        -webkit-transition: opacity 400ms ease-in;
        -moz-transition: opacity 400ms ease-in;
        transition: opacity 400ms ease-in;
        pointer-events: none;
        }
    .modalDialog:target {
        opacity:1;
        pointer-events: auto;
        }
    .modalDialog > div {
        width: 400px;
        position: relative;
        margin: 10% auto;
        padding: 5px 20px 13px 20px;
        border-radius: 10px;
        background: #fff;
        background: -moz-linear-gradient(#fff, #999);
        background: -webkit-linear-gradient(#fff, #999);
        background: -o-linear-gradient(#fff, #999);
        }
    .close {
        background: #606061;
        color: #FFFFFF;
        line-height: 25px;
        position: absolute;
        right: -12px;
        text-align: center;
        top: -10px;
        width: 24px;
        text-decoration: none;
        font-weight: bold;
        -webkit-border-radius: 12px;
        -moz-border-radius: 12px;
        border-radius: 12px;
        -moz-box-shadow: 1px 1px 3px #000;
        -webkit-box-shadow: 1px 1px 3px #000;
        box-shadow: 1px 1px 3px #000;}
    .close:hover { background: #00d9ff; 
                   }

在我的asp页面,我有以下锚标记,这是用来显示弹出:

<a href="#openModal" id="DialogLink" style="color: #FFFFFF; font-weight: bold">Register</a>

现在的问题是:

因为这是注册表单,我想现有的电子邮件id的服务器端验证。如果用户输入的email id已经在数据库中存在,我想重新打开上面的模态对话框,并提示email id已经存在。

我无法重新打开该对话框。是否有任何方法来做到这一点使用js?

模态对话框的教程在网站上:点击这里

用于显示模态对话框:点击这里

使用js打开模态对话框

我们可以使用ajax....实现这一点请查看下面的示例代码

$("#btnSubmit").live("click",(function(e) {
        var emailAddress = $.trim($('#txtEmailAddress').val());
        try
        { 
          var reqUrl = "http://mysite/Sample/Sample.aspx?post=true";
          var jqXHRresponse;
          var request = $.ajax({
                      url: reqUrl,
                      type: "POST",
                      data: {email:emailAddress},
                      dataType: 'json',
                      success:function (data, status, jqXHR) { 
                              jqXHRresponse = JSON.parse(jqXHR.responseText); 
                              if(jqXHRresponse.result == 'success')
                              {
                                /Do Something/
                              }
                              else if(jqXHRresponse.result == 'emailexist')
                              {
                                 DisplayErrorMessages('Email Already Exist');
                              }
                      });
  return false; })); 
c#

protected override void OnInit(EventArgs e)
{
  if (Request.Params["post"] == "true")
  {
    submitValues(Request.Params["email"]);
  }
}
public void submitValues(string email)
{
 string returnValue = string.Empty;
 //Call DB and send response back
 Response.Write("{'"result'":'"" + retrunValue+ "'"}");
 Response.End();
}