分享

.net 点击文本框显示选择时间

 周旋图书馆 2014-07-29
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");
       
    }
 

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约