javascript - 如何在页面加载中弹出对话框
问题描述
我在 aspx 中创建了一个如下所示的对话框:
<div id="IsAccountingOk" class="modalDialog">
<div>
<a href="#close" title="Close" class="close">X</a><br />
<asp:Label ID="lblIsAccountingOkHeader" runat="server" Text="Kassekladde:" Font-Size="Large"></asp:Label><br /><br />
<asp:Label ID="lblMessage" runat="server" Text="Der skal først vælges regnskabsår!"></asp:Label><br />
<br />
<asp:Button ID="btnIsAccountingOK" runat="server" Text="Ok" OnClick="btnIsAccountingOK_Click"/>
</div>
</div>
并且样式如下图所示:
.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;
}
我的问题是:如何通过 Page_Load 中的代码弹出此对话框 - 无需用户单击按钮?
也许它可以通过 JavaScript 来完成。
我还在javascript中尝试了以下内容:
$(document).ready(function () {
$('#IsAccountingOk').show();
});
但是当我使用上述方法时 - DIV 上的所有内容都被阻止 - 这不是意图:-(
有关更多信息,我可以通过如下所示的按钮告诉我它已经开始工作:
<asp:Button ID="btnIsAccountingOk" Text="Der skal først vælges et regnskabsår" runat="server" PostBackUrl="#IsAccountingOk"/><br />
更多信息:我在 sitepage.master 中添加了以下行:
<script type="text/javascript" src="scripts/jquery-3.3.1.js"></script>
它帮助很大。
但
提前致谢。问候迈克尔
解决方案
页面加载时没有要处理的事件处理程序。
$(document).ready(function() {
//code here
});
您可以使用 $(document).ready() 它会在 DOM 准备好时运行代码并且它不会等待窗口加载(图像、iframe...)
推荐阅读
- playframework - 在模块中播放 WS 客户端
- ruby-on-rails - 将 Heroku 中的 Rails API 设置为 Procfile 的开发和影响?
- html - HTML 中的嵌入式 CSS - 根据不同的单词更改单词颜色
- android - linux mint - android studio 模拟器进程被杀死
- python - 复杂函数的双重积分
- c++ - 什么时候创建本地静态对象?
- java - 我正在尝试使用 Datastax 4.2.2 编写一个 DAO 接口,但是遇到了几个编译错误
- google-app-engine - 使用 Terraform 创建 App Engine 应用程序时出错
- xlsxwriter - 保护工作表但仍允许调整列大小
- vue.js - vee-validate - 如何在外部文件中添加规则