昨天想做一个时间选择的textbox,当onfocus时,Calendar控件visible=true,供用户选择日期;当onblur(失去焦点时),Calendar控件visible=false消失。
按照高手指点:
在HTML里
HTML code
<div id="dv" style="display: none;"> <asp:Calendar id="Calendar1" runat="server"></asp:Calendar> </div>
cs里
C# code
this.TextBox1.Attributes.Add("onfocus","javascript:document.getElementById('dv').style.display = 'block'"); this.TextBox1.Attributes.Add("onblur","javascript:document.getElementById('dv').style.display = 'none'");
可以实现calendar控件的隐藏、显示,但calendar控件选择的日期无法赋予textbox。即 Calendar1_SelectionChanged()不执行了。这该如何解决?
还望高手再次指点一下!不胜感激。
------解决方案--------------------------------------------------------
- C# code
protected void Page_Load(object sender, EventArgs e) { Stime.Attributes.Add("onfocus", "javascript:document.getElementById('dv1').style.display = 'block'"); //Stime.Attributes.Add("onblur", "javascript:document.getElementById('dv1').style.display = 'none'"); } protected void Calendar1_SelectionChanged(object sender, EventArgs e) { Stime.Text = Calendar1.SelectedDate.ToString("d"); Response.Write("<script>document.getElementById('dv1').style.display = 'none';</script>"); }