aspx页面代码如下:
<script language="javascript" type="text/javascript"> function getAbsolutePosition(element) { var point = { x: element.offsetLeft, y: element.offsetTop }; if (element.offsetParent) { var parentPoint = this.getAbsolutePosition(element.offsetParent); point.x += parentPoint.x; point.y += parentPoint.y; } return point; } function myclick() { var myTextbox = document.getElementById("<%=myRegisterTime.ClientID %>"); var point1 = getAbsolutePosition(myTextbox); document.getElementById("caDiv").style.display = "block"; document.getElementById("caDiv").style.left = point1.x; document.getElementById("caDiv").style.top = point1.y; } function divonclick() { document.getElementById("caDiv").style.display = "none"; } </script> 时间:<asp:TextBox ID="myRegisterTime" runat="server" width="100"></asp:TextBox>
<div id="caDiv" style="display:none; position: absolute;" onclick="divonclick()"> <asp:Calendar ID="Calendar1" runat="server" BackColor="#FFFFCC" BorderColor="#FFCC66" BorderWidth="1px" DayNameFormat="Shortest" Font-Names="Verdana" Font-Size="8pt" ForeColor="#663399" Height="200px" onselectionchanged="Calendar1_SelectionChanged" ShowGridLines="True" Width="220px"> <DayHeaderStyle BackColor="#FFCC66" Font-Bold="True" Height="1px" /> <NextPrevStyle Font-Size="9pt" ForeColor="#FFFFCC" /> <OtherMonthDayStyle ForeColor="#CC9966" /> <SelectedDayStyle BackColor="#CCCCFF" Font-Bold="True" /> <SelectorStyle BackColor="#FFCC66" /> <TitleStyle BackColor="#990000" Font-Bold="True" Font-Size="9pt" ForeColor="#FFFFCC" /> <TodayDayStyle BackColor="#FFCC66" ForeColor="White" /> </asp:Calendar> </div> aspx.cs 添加如下代码:
myRegisterTime.Attributes.Add("onfocus", "javascript:myclick()");//文件中的page_load事件中:
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{ myRegisterTime.Text = Calendar1.SelectedDate.ToString("yyyy-MM-dd"); } |
|