close

日期選擇器是很普遍的用法,

可以避免user輸入不同的日期格式~

 

效果

View post on imgur.com

 

 

1.引入jQuery、jQuery UI的js檔、jQuery UI的css檔

<script src="../Scripts/jquery-1.12.4.min.js"></script>

<script src="../Scripts/jquery-ui-1.12.1/jquery-ui-1.12.1.custom/jquery-ui.js"></script>

<link href="../Scripts/jquery-ui-1.12.1/jquery-ui-1.12.1.custom/jquery-ui.css" rel="stylesheet" />

 

2.ASP.NET Webform的Textbox範例

<asp:TextBox ID="txtStartDate" runat="server"></asp:TextBox>

<asp:TextBox ID="txtEndDate" runat="server"></asp:TextBox>

 

3.撰寫js

datepicker的預設格式為 日/月/年

以下改成 : 年/月/日

較符合一般使用習慣

 <script>
        $(document).ready(function(){
            $('#<% =txtStartDate.ClientID %>').datepicker({dateFormat:'yy/mm/dd'});
            $('#<% =txtEndDate.ClientID %>').datepicker(dateFormat:'yy/mm/dd'});
        });
 </script>

 

arrow
arrow
    全站熱搜

    Kenny Lin 發表在 痞客邦 留言(0) 人氣()