I have a asp:textbox , how can i set its minimum date to today using javascript:
我有一个asp:文本框,如何使用javascript将其最小日期设置为今天:
With C# I am doing it like this and it works fine..but I have to do it using Js/Jquery
使用C#我这样做,它工作正常..但我必须使用Js / Jquery
DateTime date = DateTime.Today.Date;
String today = date.ToString("yyyy-MM-dd");
tourStartDate.Attributes["min"] =today;
<asp:TextBox Width="95%" ID="tourStartDate" runat="server" TextMode="Date" onchange="SetDate()"></asp:TextBox></td>
2 个解决方案
#1
0
you need to put the ClientIdMode = static
in the server control to get the static Id.
您需要将ClientIdMode = static放在服务器控件中以获取静态Id。
<asp:TextBox Width="95%" ID="tourStartDate" ClientIdMode = "static" runat="server" TextMode="Date" onchange="SetDate()"></asp:TextBox>
Jquery: Set today in attribute.
Jquery:今天设置属性。
$("#tourStartDate").attr("min", (new Date()));
EDIT:
Can you try <input type="date" min="2015-07-01" max="2015-10-20">
你能尝试
JQuery:
$("#tourStartDate").attr("min", (new Date()).toISOString().substring(0,10));
Make sure your doc type is html ( for HTML 5 controls)
确保您的doc类型是html(对于HTML 5控件)
EDIT2 :
JavaScript :
document.getElementById('tourStartDate').setAttribute('min', (new Date()).toISOString().substring(0,10));
#2
0
On Code Behind C#:
关于C#背后的代码:
tourStartDate.Attributes["max"] = DateTime.Now.ToString("yyyy-MM-dd");
VB.net:
tourStartDate.Attributes("max") = Now.ToString("yyyy-MM-dd")
#1
0
you need to put the ClientIdMode = static
in the server control to get the static Id.
您需要将ClientIdMode = static放在服务器控件中以获取静态Id。
<asp:TextBox Width="95%" ID="tourStartDate" ClientIdMode = "static" runat="server" TextMode="Date" onchange="SetDate()"></asp:TextBox>
Jquery: Set today in attribute.
Jquery:今天设置属性。
$("#tourStartDate").attr("min", (new Date()));
EDIT:
Can you try <input type="date" min="2015-07-01" max="2015-10-20">
你能尝试
JQuery:
$("#tourStartDate").attr("min", (new Date()).toISOString().substring(0,10));
Make sure your doc type is html ( for HTML 5 controls)
确保您的doc类型是html(对于HTML 5控件)
EDIT2 :
JavaScript :
document.getElementById('tourStartDate').setAttribute('min', (new Date()).toISOString().substring(0,10));
#2
0
On Code Behind C#:
关于C#背后的代码:
tourStartDate.Attributes["max"] = DateTime.Now.ToString("yyyy-MM-dd");
VB.net:
tourStartDate.Attributes("max") = Now.ToString("yyyy-MM-dd")