日历上添加活动通知(Asp.net)
<div id="calendar_contain"> </div> <script language="javascript" src="js/event.js"></script> <link href="css/gallery.css" rel="stylesheet" type="text/css" /> <script type="text/javascript"> $.ajax({ type: "post", datatype: "json", url: "Handler/DHallZTinfo.ashx", async: false, //异步发送 success: function(rdata) { rdata = $.parseJSON(rdata); //转换成json格式 for (var item = 0; item < rdata.length; item++) { hashMap.Set("" + rdata[item].time + "", "<a href=" + rdata[item].url + ">" + rdata[item].title + "</a>"); } } }); function Offset(e) { var t = e.offsetTop; var l = e.offsetLeft; var w = e.offsetWidth; var h = e.offsetHeight - 2; while (e = e.offsetParent) { t += e.offsetTop; l += e.offsetLeft; } return { top: t, left: l, width: w, height: h } } function itemShow(id) { document.getElementById(id + "s").className = "calendarEventHov"; document.getElementById(id).style.display = "block"; } function itemHide(id) { document.getElementById(id + "s").className = "calendarEvent"; document.getElementById(id).style.display = "none"; } //转换日期成字符串,例如2008年8月31日转换成‘20080831‘ function dateToString(date) { return date.getFullYear() + this.digitFix(date.getMonth() + 1, 2) + this.digitFix(date.getDate(), 2); } //修正当前单数的月份为两位,例如‘8‘->‘08‘ function digitFix(number, count) { var _string = number + ""; var _count = count - _string.length; for (var i = 0; i < _count; i++) _string = "0" + _string; return _string; } var monthArray = ["1月", "2月", "3/月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"]; </script> <script src="js/JCalendar.js" type="text/javascript"></script> <script type="text/javascript"> document.getElementById("calendar_contain").innerHTML = new JCalendar().show(); JCalendar.update(0); $(function() { /* 日历 右上角按钮*/ $(‘.preMonth‘).mouseover(function() { $(this).attr(‘class‘, ‘preMonthHov‘); }).mouseout(function() { $(this).attr(‘class‘, ‘preMonth‘); }); $(‘.nextMonth‘).mouseover(function() { $(this).attr(‘class‘, ‘nextMonthHov‘); }).mouseout(function() { $(this).attr(‘class‘, ‘nextMonth‘); }); /*显示事件安排弹出框*/ $(‘.calendarEvent‘).mouseover(function() { $(this).css(‘z-index‘, ‘1000‘); $(this).attr(‘class‘, ‘calendarEventHov‘); $(this).find(‘.calendarShowBox‘).show(); }).mouseout(function() { $(this).css(‘z-index‘, ‘0‘); $(this).attr(‘class‘, ‘calendarEvent‘); $(this).find(‘.calendarShowBox‘).hide(); }); }); </script>
///
<%@ WebHandler Language="C#" Class="DHallZTinfo" %> using System; using System.Web; using System.Data; public class DHallZTinfo : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; DataTable dtdhallInfo = SystemBLL.information.Instance.selectinfobyzongid(733, 0);//绑定日历上要显示的通知 context.Response.Write(GetJson(dtdhallInfo)); } /// <summary> /// 编写json格式 /// </summary> /// <param name="dt"></param> /// <returns></returns> private string GetJson(DataTable dt) { string url = ""; string strlv = ""; string flag = ""; string strid = ""; System.Text.StringBuilder _sb = new System.Text.StringBuilder(); if (dt == null || dt.Rows.Count == 0) return "[]"; _sb.Append("["); int tmpRows = dt.Rows.Count; for (int i = 0; i < tmpRows; i++) { url = dt.Rows[i]["info_url"].ToString(); strlv = dt.Rows[i]["info_lb"].ToString(); flag = dt.Rows[i]["info_zong"].ToString(); strid = dt.Rows[i]["info_id"].ToString(); if (url == "#") { url = "Show.aspx?info_lb=" + strlv + "&info_id=" + strid + "&flag=" + flag; } _sb.Append("{ \"time\":\"" + GetTimeinfo(dt.Rows[i].Field<DateTime>("info_addtime")) + "\", \"url\":\"" + url + "\", \"title\":\"" + dt.Rows[i].Field<string>("info_title") + "\"}"); } _sb.Append("]"); System.Collections.Generic.List<object> list = new System.Collections.Generic.List<object>(); foreach (var item in dt.AsEnumerable()) { list.Add(new { id = item.Field<int>("id"), url = GetUrl("", "", "", "") }); } // var jsonstr = Newtonsoft.Json.JsonConvert.SerializeObject(dt); // var jsonstr2 = Newtonsoft.Json.JsonConvert.SerializeObject(list); return _sb.ToString(); } private string GetUrl(string strlv, string strid, string flag, string url) { if (url == "#") { return url = "Show.aspx?info_lb=" + strlv + "&info_id=" + strid + "&flag=" + flag; } return url; } /// <summary> /// 获取时间 /// </summary> /// <param name="time"></param> /// <returns></returns> public string GetTimeinfo(DateTime time) { return time.ToString("yyyyMMdd"); } public bool IsReusable { get { return false; } } }
//效果:
不知道怎么上传js文件。需要的可以问我要先关文件~~
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。