如何在aspx页面中使用datepicker?

时间:2013-12-09 06:44:00

标签: c# javascript jquery asp.net

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

在html页面中使用相同的代码,它使用相同的浏览器。使用aspx页面,此代码无效。

有谁能告诉我需要对此代码进行哪些更改?。

2 个答案:

答案 0 :(得分:0)

用此替换您的Javascript。

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

答案 1 :(得分: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>