周数点击周数

时间:2014-01-06 04:52:37

标签: javascript asp.net calendar

有没有办法在asp.net或使用javascript,当有人点击日历上显示的周数时,我可以在标签上获取日期(星期一到星期五)?

2 个答案:

答案 0 :(得分:4)

试试这个jsFiddle示例。

$(".calendar").datepicker({
    showWeek: true,
    onSelect: function(dateText, inst) {
        dateFormat: "'Week Number '" + $.datepicker.iso8601Week(new Date(dateText)),
        $(this).val('Week:' + $.datepicker.iso8601Week(new Date(dateText)));
    }
});​

答案 1 :(得分:4)

这是asp.net中的服务器端解决方案

标记

<asp:Label ID="Label1" runat="server" Text="" />
<asp:Calendar runat="server" ID="Calendar1" OnSelectionChanged="Calendar1_SelectionChanged" />

背后的代码

protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
    DateTime input = Calendar1.SelectedDate;
    int delta = DayOfWeek.Sunday - input.DayOfWeek;
    DateTime firstDay = input.AddDays(delta);

    for (int i = 0; i < 7; i++)
      Label1.Text += ((DateTime)(firstDay.Add(new TimeSpan(i, 0, 0, 0)))).ToShortDateString() + " -- ";
}