简体   繁体   English

如何在aspx页面中使用datepicker?

[英]how to use datepicker in aspx page?

I am using the following code in an ASPX page for a date picker: 我在ASPX页面中使用以下代码作为日期选择器:

 <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" />

Using the same code in an html page it is working with the same browser. 在html页面中使用相同的代码,即可在相同的浏览器上使用。 with the aspx page this code is not working. 与aspx页面此代码不起作用。

Can anyone tell me what changes i need to make to this code?. 谁能告诉我我需要对该代码进行哪些更改?

Replace your Javascript with this. 以此替换您的Javascript。

 <script language="javascript" type="text/javascript">
    $(document).ready(function () {
        $("#<%= txtToDate.ClientID %>").datepicker({ dateFormat: "dd/mm/yy" }).val();
    });
</script>  
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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM