一、前言

      前几天做项目的时候要用到日期控件,但是在ASP.NET中,没有封装日期控件,第一想法就是百度一下喽~,下面给大家分享如何使用这个控件,扩充一下自己的代码库~~~~

二、内容介绍

      首先需要大家下载一个DatePicker的JavaScript的文件,解压文件包,放于所需的项目文件夹下,直接放到JS的文件夹下(没有的话直接粘贴进来就可以),然后在要用的界面里面引用这个DatePicker的WdatePicker.JS文件。

【Asp.Net】日期控件DatePicker使用_datepicker

图一 界面展示

前台代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="datepickertest.aspx.cs" Inherits="DatePickertest2.datepickertest" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>文本框</title>
    <%--引用DatePicker的JS文件--%>
    <script src="My97DatePicker/WdatePicker.js"></script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <%--添加文本框--%>
        <asp:TextBox ID="TextBox1" runat="server" onclick="WdatePicker()"></asp:TextBox>
        <input id="Text1" type="text" class="Wdate" onFocus="WdatePicker({lang:'zh-cn'})" />
        <input class="Wdate" id="d1" onclick="WdatePicker()" />
    </div>
    </form>
</body>
</html>

效果图:

【Asp.Net】日期控件DatePicker使用_百度_02

图二 效果图

三、小结

      这个时间控件非常实用,基本在每一个界面上面都会见到这个控件,是很好的操作,希望能给您带来帮助。