我似乎无法使用按钮关闭模式,网页加载并自动弹出带有覆盖的模式。但是,我想在自动加载页面时不使用按钮打开模式。
这是我的模式和打开和关闭按钮:
模态,叠加和内容:
<div id='overlay'>
</div>
<div id='modal'>
<div id='content' style="background-color: #767A8F; font-family: Segoe UI; font-size: Medium; z-index: 1; left: 280px; top: 800px; position: fixed; height: 160px; width: 20px;">
<br />
<Uc2:EditCurrentSet ID="EditCurrentSet" runat="server" />
</div>
关闭按钮:
<asp:Button ID="close" class="close" runat="server" BackColor="#525663" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1pt" Font-Size="Large" ForeColor="White" Style="font-family: Segoe UI; margin-left: 0px; position: absolute; top: 418px; left: 5px; width: 64px; height: 44px; z-index: 1; margin-top: 0px; right: 112px;" Text="Cancel" />
打开按钮:
<asp:Button class="open" ID="open" runat="server" BackColor="#525663" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1pt" CommandName="MoveNext" Font-Size="Large" ForeColor="White" Style="font-family: Segoe UI; margin-left: 0px; position: relative; top: 25px; left: -25px; width: 152px; height: 41px;" Text="Edit Information" />
和 JavaScript 代码:
<script src="js/jquery-ui-1.8.14.js" type="text/javascript"></script>
<script>
var modal = (function () {
var method = {},$overlay,$modal,$content,$close,$open;
// Center the modal in the viewport
method.center = function () {
var top, left;
top = Math.max($(window).height() - $modal.outerHeight(), 0) / 2;
left = Math.max($(window).width() - $modal.outerWidth(), 0) / 2;
$modal.css({ top: top + $(window).scrollTop(), left: left });
};
// Open the modal
method.open = function (settings) { };
// Close the modal
method.close = function () { };
return method;
} ());
$overlay = $('<div id="overlay"></div>');
$modal = $('<div id="modal"></div>');
$content = $('<div id="content"></div>');
$close = $('<a id="close" href="#">close</a>');
$open = $('<a id="open" href="#">open</a>');
$modal.hide();
$overlay.hide();
$modal.append($content, $close);
$(document).ready(function () {
$('body').append($overlay, $modal);
});
method.center = function () {
var top, left;
top = Math.max($(window).height() - $modal.outerHeight(), 0) / 2;
left = Math.max($(window).width() - $modal.outerWidth(), 0) / 2;
$modal.css({
top: top + $(window).scrollTop(),
left: left + $(window).scrollLeft()
});
};
method.open = function (settings) {
$content.empty().append(settings.content);
$modal.css({
width: settings.width || 'auto',
height: settings.height || 'auto'
})
method.center();
$(window).bind('resize.modal', method.center);
$modal.show();
$overlay.show();
};
method.close = function () {
$modal.hide();
$overlay.hide();
$content.empty();
$(window).unbind('resize.modal');
};
$open.click(function (e) {
e.preventDefault();
method.open();
});
$close.click(function (e) {
e.preventDefault();
method.close();
});
modal.open({ content: "Howdy" });
modal.open({ content: "<p>Howdy</p>" });
modal.open({ content: $("<p>Howdy</p>"), width: "500px", height: "200px" });
// Ajax
$.get('ajax.html', function (data) {
modal.open({ content: data });
});
</script>