我使用Trent Richardson在模态弹出窗口中创建的DateTimePicker插件来选择存档项目的日期。当模态弹出时,一切正常。在这个模态中,我有两个按钮:存档和取消。 如果我选择一个日期并按下存档,一切正常,在下一次弹出时,datetimepicker工作正常。 但是,如果我按下取消,下次使用弹出窗口时,datetimepicker不起作用。最奇怪的是,我有另一个弹出窗口显示也有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>
任何想法都会受到赞赏。
答案 0 :(得分:0)
请尝试使用以下代码。当您在模态上加载内容时,您需要使用可以使用以下代码实现的实时功能。
$('body').on('click','#chooseDate',function(){
$(this).datetimepicker();
});
答案 1 :(得分:0)
彻底清理脚本文件(不再从局部视图传递它们)后,它就会整理出来。