【发布时间】:2017-05-07 05:13:02
【问题描述】:
更新:对于仍然可能阅读此内容的任何人,我使用了一种完全不同的方式来做到这一点。使用 AjaxToolkit 的日历扩展器,我能够轻松地动态添加日历并使用 Javascript 更改不同日期输入的格式,以便日历扩展器可以读取它。如果您尝试做与我类似的事情,强烈建议您使用 AjaxToolkit 路线。
我为评论类动态创建了日历控件(asp:Calendar)、按钮和下拉列表。 Comment Class 将始终在其中包含一个文本框,但如果文本框的 ID/属性标签是 DOB 或生日或类似的东西,这些其他控件将动态创建。
到目前为止,日历、下拉列表和其中一个按钮都可以使用,但我在使用最后一个按钮时遇到了问题。目前,我动态添加了一个脚本,用于其中一个按钮来显示和隐藏包含该日历、下拉列表和相关按钮的 div,效果非常好。我正在尝试在按下按钮时添加另一个脚本触发器,以从日历中获取选定的日期并将其放入文本框中。
现在,我只是想访问日历。我正在使用如下代码:
function use_calendarDate(){
var calendarDate = '<%=question128_Cal1.SelectedDate%>';
alert(calendarDate);
}
我在另一个类似的问题中发现了这个函数,但它不是获取日期,而是将 作为字符串放入警报框中。
这个LINK 正是我想要做的事情,但我得到了不同的结果。谁能帮我解决我在这里做错的事情?
有趣的是,当我使用
var calendarDate = question128_Cal1.SelectedDate;
或
var calendarDate = question128_Cal1.value;
我的警告框告诉我未定义。
提前致谢。
如果需要,我的日历控件是这样创建的:
在 Page_Init 中
Dim calendar1 As New Calendar
Call BuildCalendar(calendar1)
calendarDiv.Controls.Add(calendar1)
这是上面引用的函数。
Private Sub BuildCalendar(ByRef calendar1 As Calendar)
calendar1.ID = "Cal1"
calendar1.SelectedDate = DateTime.Today
calendar1.Attributes.Add("runat", "server")
calendar1.Attributes.Add("OnClientDateChanged", "onDateChange")
calendar1.Attributes.Add("borderwidth", "2px")
calendar1.Attributes.Add("BackColor", "White")
calendar1.Attributes.Add("width", "200px")
calendar1.Attributes.Add("ForeColor", "Black")
calendar1.Attributes.Add("Height", "180px")
calendar1.Attributes.Add("Font-Size", "8pt")
calendar1.Attributes.Add("Font-Names", "Verdana")
calendar1.Attributes.Add("BorderColor", "#999999")
calendar1.Attributes.Add("BorderStyle", "Outset")
calendar1.Attributes.Add("DayNameFormat", "FirstLetter")
calendar1.Attributes.Add("CellPadding", "4")
calendar1.Attributes.Add("ShowNextPrevMonth", "True")
calendar1.Attributes.Add("SelectionMode", "Day")
calendar1.Attributes.Add("ShowTitle", "false")
calendar1.Attributes.Add("OnSelectionChanged", "Calendar_SelectionChanged")
calendar1.TodayDayStyle.ForeColor = Drawing.Color.Black
calendar1.Attributes.Add("todaydaystyle-backcolor", "#cccccc")
calendar1.Attributes.Add("selectorstyle-backcolor", "#cccccc")
calendar1.NextPrevStyle.VerticalAlign = VerticalAlign.Bottom
calendar1.Attributes.Add("dayheaderstyle-font-size", "7pt")
calendar1.Attributes.Add("dayheaderstyle-font-bold", "true")
calendar1.Attributes.Add("dayheaderstyle-backcolor", "#cccccc")
calendar1.Attributes.Add("selecteddaystyle-font-bold", "true")
calendar1.Attributes.Add("selecteddaystyle-forecolor", "White")
calendar1.Attributes.Add("selecteddaystyle-backcolor", "#666666")
calendar1.Attributes.Add("titlestyle-font-bold", "true")
calendar1.TitleStyle.BorderColor = Drawing.Color.Black
calendar1.Attributes.Add("titlestyle-backcolor", "#999999")
calendar1.Attributes.Add("weekenddaystyle-backcolor", "#ffffcc")
calendar1.OtherMonthDayStyle.BackColor = Drawing.Color.Gray
End Sub
【问题讨论】:
标签: javascript asp.net vb.net calendar