2013-12-09 89 views
0

我正在使用的ASPX页面下面的代码日期选择器:如何在aspx页面中使用datepicker?

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"> 

    <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" /> 
    <script src="http://code.jquery.com/jquery-1.9.1.js"></script> 
    <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script> 

<title></title> 
<script type="text/javascript"> 
    $(function() {   
     $("#txtToDate").datepicker({ dateFormat: "dd/mm/yy" }).val(); 
    }); 

</script> 

    </asp:Content> 

    <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"> 

    <asp:Label ID="Label33" runat="server" Font-Bold="True" ForeColor="Black" 
     Text="To Date"></asp:Label> 
    <input id="txtToDate" runat="server" 
onblur="if(this.value == '') { this.value='dd/mm/yyyy'}" 
onfocus="if (this.value=='dd/mm/yyyy') {this.value=''}" type="text" 
value="dd/mm/yyyy" /> 

使用它正在与同一个浏览器的HTML页面相同的代码。与aspx页面此代码不起作用。

任何人都可以告诉我需要对此代码进行哪些更改吗?

回答

0

用这个替换你的Javascript。

<script language="javascript" type="text/javascript"> 
    $(document).ready(function() { 
     $("#<%= txtToDate.ClientID %>").datepicker({ dateFormat: "dd/mm/yy" }).val(); 
    }); 
</script> 
+0

是它的工作,谢谢。 – Raghuveera

0
The above code is working for me. Please check it my code below 


<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title></title> 
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" /> 
    <script src="http://code.jquery.com/jquery-1.9.1.js"></script> 
    <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script> 

    <script type="text/javascript"> 
     $(function() { 
      $("#txtToDate").datepicker({ dateFormat: "dd/mm/yy" }).val(); 
     }); 

    </script> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <div> 
     <asp:Label ID="Label33" runat="server" Font-Bold="True" ForeColor="Black" Text="To Date"></asp:Label> 
     <input id="txtToDate" runat="server" onblur="if(this.value == '') { this.value='dd/mm/yyyy'}" 
      onfocus="if (this.value=='dd/mm/yyyy') {this.value=''}" type="text" value="dd/mm/yyyy" /> 
    </div> 
    </form> 
</body> 
</html> 
+0

由于文本框控件具有'runat = server',因此它们的id在浏览器中得到更改检查,所以您需要添加class或id需要像这样执行'$(“#<%= txtToDate.ClientID%>”)' –

+0

但是在这里他正在使用输入类型。我认为不需要客户端ID。如果我们使用的是,则需要客户端id .. –

+0

是的,您的代码在html页面中工作,但不在aspx页面中。 – Raghuveera