我在模态弹出窗口中使用 Trent Richardson 制作的 DateTimePicker 插件来选择归档项目的日期。当模态弹出时,一切正常。在这个模式中,我有两个按钮:存档和取消。如果我选择一个日期并按存档,一切正常,在下一个弹出窗口中,日期时间选择器工作正常。但是,如果我按下取消,下次我使用弹出窗口时,日期时间选择器将不起作用。最奇怪的是,我有另一个弹出窗口来显示也有日期时间选择器的存档项目。如果我在任一弹出窗口中取消该操作,则 datetimpicker 将不会显示在两个弹出窗口中。
这是初始化弹出窗口的代码javascript:
var modalBackground = $("#modalBackground");
var Notifications_ArchiveHolder = $("#Notifications_ArchiveHolder");
var Notifications_ShowArchivePopupHolder = $("#Notifications_ShowArchivePopupHolder");
var ArchiveURL = "@Url.Action("Archive")";
var ShowArchiveUrl = "@Url.Action("ShowArchive", "Notifications")";
function ArchivePopup() {
$.get(ArchiveURL, function (content) {
if (Notifications_ArchiveHolder.html().length <= 10) {
Notifications_ArchiveHolder.html(content);
}
})
InitArchivePopup();
}
function InitArchivePopup() {
modalBackground.show();
//set up positon
var h = $(window).height();
var w = $(window).width();
var hh = Notifications_ArchiveHolder.height();
var hw = Notifications_ArchiveHolder.width();
var posx = (h / 2) - 100;
var posy = (w / 2) - 200;
Notifications_ArchiveHolder.css("position", "fixed");
Notifications_ArchiveHolder.css("top", posx);
Notifications_ArchiveHolder.css("left", posy);
Notifications_ArchiveHolder.show();
$("body").css("overflow", "hidden");
}
function Cancel_Archive() {
Notifications_ArchiveHolder.hide();
Notifications_ArchiveHolder.html("");
modalBackground.hide();
}
一个 div 用于背景,另一个用于托管弹出窗口:
<div id="modalBackground" class="graphicScreen" style="display: none; position: fixed; top: 0px; left: 0px;"></div>
<div id="Notifications_ArchiveHolder" style="background-color: white; display: none; z-index: 9999;"></div>
以及在弹出窗口中呈现的部分视图的代码:
<link rel="stylesheet" href="@Url.Content("~/Resources/styles/Notifications/NotificationsPage.css")" />
@using (@Html.BeginForm("Archive", "Notifications", FormMethod.Post))
{
<div class="popupTitle">
Archive notifications
</div>
<div class="popupNotifications">
<span>Archive to date (inclusive)</span>
<input type="text" name="olderThan" id="chooseDate" />
</div>
<div style="margin: 15px">
<input class="goVariant" type="submit" value="Archive" />
<input id="cancelBtn" class="goVariant" type="button" value="Cancel" onclick="Cancel_Archive()" />
@*<div class="tooltip_Holder" keyword="notif_admin_archive" onclick="showToolTip();"></div>*@
</div>
}
<link href="@Url.Content("~/Resources/styles/jquery-ui-timepicker-addon.css")" rel="stylesheet" />
<script src="@Url.Content("~/Resources/JQuery/DateTimePicker/jquery-1.9.1.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Resources/JQuery/DateTimePicker/jquery-ui.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Resources/JQuery/DateTimePicker/jquery-ui-timepicker-addon.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Resources/JQuery/DateTimePicker/jquery-migrate-1.2.1.js")"></script>
<script>
$(document).ready(function () {
$('#chooseDate').datetimepicker();
})
</script>
任何想法将不胜感激。