/// /// /// DateTimeBox = function () { this.ApplicationPath = ""; this.ControlID = "Window_DateTimeBox"; this.ParentElement = null; //要加入的父容器 this.Isbgiframe = false; var My = this; var CalendarID = My.ControlID + "_Calendar"; var TimespinnerID = My.ControlID + "_Timespinner"; var cmdSaveID = My.ControlID + "_cmdSave"; var cmdToDayID = My.ControlID + "_cmdToDay"; var cmdCloseID = My.ControlID + "_cmdClose"; var SelectDate = new Date(); var TextBox = null; //#region 加载 this.Load = function () { Init(); $(document).click(function () { if (window.event.srcElement.id == My.ControlID) return; if ($(window.event.srcElement).parents("#" + My.ControlID).length == 0) $("#" + My.ControlID, My.ParentElement).hide(); }); //选择 $("#" + cmdSaveID, My.ParentElement).click(function () { TextBox.value = SelectDate.localeFormat("yyyy-MM-dd") + " " + $("#" + TimespinnerID).val(); $("#" + My.ControlID, My.ParentElement).hide(); }); //关闭 $("#" + cmdCloseID, My.ParentElement).click(function () { $("#" + My.ControlID, My.ParentElement).hide(); }); //今天 $("#" + cmdToDayID, My.ParentElement).click(function () { SelectDate = new Date(); $("#" + CalendarID, My.ParentElement).calendar("moveTo", new Date()); }); } //#endregion //#region 初始化 function Init() { if (My.ParentElement == null) My.ParentElement = $(document.body); if ($("#" + My.ControlID, My.ParentElement).length > 0) return; var htmlString = new Sys.StringBuilder(); htmlString.append(""); My.ParentElement.append(htmlString.toString()); $("#" + CalendarID, My.ParentElement).calendar({ onSelect: function (d) { SelectDate = d; } }); $("#" + TimespinnerID, My.ParentElement).timespinner(); $("#" + My.ControlID, My.ParentElement).draggable(); if (My.Isbgiframe == true) $("#" + My.ControlID, My.ParentElement).bgiframe(); $("#" + TimespinnerID, My.ParentElement).timespinner("setValue", new Date().localeFormat("HH:mm")); } //#endregion //#region 显示 this.Show = function (obj) { TextBox = obj; var position = $(TextBox).offset(); var top=position.top + $(TextBox).height(); var left=position.left; $("#" + My.ControlID, My.ParentElement).css("top", top).css("left", left); var value = obj.value; if (value.length >= 10) { var a = Date.parseInvariant(value.substr(0, 10), "yyyy-MM-dd"); if (a != null) $("#" + CalendarID, My.ParentElement).calendar("moveTo", a); } if (value.length == 16) { var b = Date.parseInvariant(value.substr(11, 5), "HH:mm"); if (b == null) { $("#" + TimespinnerID, My.ParentElement).timespinner("setValue", new Date().localeFormat("HH:mm")); } else { $("#" + TimespinnerID, My.ParentElement).timespinner("setValue", value.substr(11, 5)); } } $("#" + My.ControlID, My.ParentElement).show(); } //#endregion }