无法使用模态窗口隐藏 div



我正在我的 asp.net 网站中构建电子邮件订阅表单,并且当用户将其名称添加到订阅列表时,我正在尝试显示模式窗口。我似乎无法让div 隐藏在页面加载上。模态在页面加载时加载,但我希望它在用户提交表单之前被隐藏。

理想情况下,这一切都将在服务器端完成,因为我不希望在提交表单之前弹出模式,并且客户端这样做可能会触发误报。

我不确定实现这一目标的最佳方法是什么,通过代码隐藏或可能的jQuery,我对此知之甚少。

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <link rel="stylesheet" href="/resources/demos/style.css">
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  <script>
  $( function() {
    $( "#dialog-message" ).dialog({
      modal: true,
      buttons: {
        Ok: function() {
          $( this ).dialog( "close" );
        }
      }
    });
  } );
  </script>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<style>
.responsive {
  width: 40%;
  height: auto;
}
</style>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<style>
img {
  display: block;
  margin-left: auto;
  margin-right: auto;
}
</style>
    <style>
        .simple-subscription-form {
  background: #000000;
  color: #94C60D;
  padding: 2rem;
  border-radius: 0;
  align-content: center
}
</style>
<style>
.simple-subscription-form.button {
  margin-bottom: 0;
  border-radius: 0 0 0 0;
}
</style>
    <style>
        #dialog-message { display: none; padding: 5px;  }
    </style>
    <style>
div.hidden {
  display: none;
}
</style>
</head>
<body bgcolor="black">
    <div class="simple-subscription-form" id="emailForm">
        <form id="email" runat="server">
                <script type="text/javascript">
        function showDiv() {
            div = document.getElementById('dialog-message');
            div.style.display = "block";
        }
    </script>
            <h4>Subscribe</h4>
            <p>Receive updates and latest news direct from our team. Simply enter your email below :</p>
            <div class="input-group"/>
            <span class="input-group-label">
                <i class="fa fa-envelope"></i>
            </span>
            <input class="input-group-field" runat="server" id="emailSignupField" type="email" placeholder="Email" required/>
            <asp:button class="button" OnClientClick="javascript:showDiv(#dialog-message);" OnClick="emailSignupForm_click" runat="server" id="submitEmailForm" Text="Sign Up Now"></asp:button>
          </form>
           <div id="dialog-message" title="Subscribed!" class="hidden" >
            <p>
             <span class="ui-icon ui-icon-circle-check" style="float:left; margin:0 7px 50px 0;"></span>
                You have been successfully added to our Mailing List
            </p>
            </div>
 </div>
</body>
</html>

</head> 之前插入<script>,这样它就不会出现故障

<script>
 $( function() {
   $('#dialog-message').dialog('close')
  } );                   
</script>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <link rel="stylesheet" href="/resources/demos/style.css">
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  <script>
  $( function() {
    $( "#dialog-message" ).dialog({
      modal: true,
      buttons: {
        Ok: function() {
          $( this ).dialog( "close" );
        }
      }
    });
  } );
  </script>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<style>
.responsive {
  width: 40%;
  height: auto;
}
</style>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<style>
img {
  display: block;
  margin-left: auto;
  margin-right: auto;
}
</style>
    <style>
        .simple-subscription-form {
  background: #000000;
  color: #94C60D;
  padding: 2rem;
  border-radius: 0;
  align-content: center
}
</style>
<style>
.simple-subscription-form.button {
  margin-bottom: 0;
  border-radius: 0 0 0 0;
}
</style>
    <style>
        #dialog-message { display: none; padding: 5px;  }
    </style>
    <style>
div.hidden {
  display: none;
}
</style>
<script>
 $( function() {
   $('#dialog-message').dialog('close')
  } );
        
    
</script>
</head>
<body bgcolor="black">
    <div class="simple-subscription-form" id="emailForm">
        <form id="email" runat="server">
                <script type="text/javascript">
        function showDiv() {
            div = document.getElementById('dialog-message');
            div.style.display = "block";
        }
    </script>
            <h4>Subscribe</h4>
            <p>Receive updates and latest news direct from our team. Simply enter your email below :</p>
            <div class="input-group"/>
            <span class="input-group-label">
                <i class="fa fa-envelope"></i>
            </span>
            <input class="input-group-field" runat="server" id="emailSignupField" type="email" placeholder="Email" required/>
            <asp:button class="button" OnClientClick="javascript:showDiv(#dialog-message);" OnClick="emailSignupForm_click" runat="server" id="submitEmailForm" Text="Sign Up Now"></asp:button>
          </form>
           <div id="dialog-message" title="Subscribed!" class="hidden" >
            <p>
             <span class="ui-icon ui-icon-circle-check" style="float:left; margin:0 7px 50px 0;"></span>
                You have been successfully added to our Mailing List
            </p>
            </div>
 </div>
</body>
</html>

最新更新