easyui-textbox 显示示年月

<!--页面部分-->javascript

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<base href="<%=basePath%>">
<meta charset="UTF-8">
    <title>Column Group - jQuery EasyUI Demo</title>
    <link rel="stylesheet" type="text/css" href="resources/js/easyui-1.5.2/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="resources/js/easyui-1.5.2/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="resources/js/easyui-1.5.2/demo.css">
    <script type="text/javascript" src="resources/js/easyui-1.5.2/jquery.min.js"></script>
    <script type="text/javascript" src="resources/js/easyui-1.5.2/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="resources/js/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="resources/js/dwView.js?time=<%=new Date().getTime()%>"></script>
    <!–[if lt IE 7]>
    <script  type="text/JavaScript" src="resources/js/json2.js"></script>
    <![endif]–>
<title>客户池</title>
<body>
      <div id="searchtb" style="padding:6px;height:auto">
           <table>
            <tr>
                  <td>
                     <input class="easyui-textbox" id="pstxt"
                     value="客户名称、物料编码" style="width: 350px;color:#A4A4A4""></input>
                    </td>
                    <td>
                          <input id="d4311" type="text" class="easyui-datebox" size="13px;" >到
                         <input id="d4312" type="text" class="easyui-datebox"   size="13px;"></input>
                    </td>
              <td>
                  <input  type="button" onclick="search()" value="查询" />
             </td>
            </tr>
        </table>
    </div>
    <table id="dwDatagrid">
    </table>
</body>
</html>css

<!--js 部分-->html

/**日期显示格式化*/
function formartDate(id){
    $('#'+id).datebox({  
        onShowPanel : function() {// 显示日趋选择对象后再触发弹出月份层的事件,初始化时没有生成月份层  
            span.trigger('click'); // 触发click事件弹出月份层  
            if (!tds)  
                setTimeout(function() {// 延时触发获取月份对象,由于上面的事件触发和对象生成有时间间隔  
                    tds = p.find('div.calendar-menu-month-inner td');  
                    tds.click(function(e) {  
                        e.stopPropagation(); // 禁止冒泡执行easyui给月份绑定的事件  
                        var year = /\d{4}/.exec(span.html())[0]// 获得年份  
                        , month = parseInt($(this).attr('abbr'), 10) + 1; // 月份  
                        $('#'+id).datebox('hidePanel')// 隐藏日期对象  
                        .datebox('setValue', year + '-' + month); // 设置日期的值  
                    });  
                }, 0);  
        },  
        parser : function(s) {// 配置parser,返回选择的日期  
            if (!s)  
                return new Date();  
            var arr = s.split('-');  
            return new Date(parseInt(arr[0], 10), parseInt(arr[1], 10) - 1, 1);  
        },  
        formatter : function(d) {  
            if (d.getMonth() == 0) {  
                return d.getFullYear()-1 + '-' + 12;  
            } else {  
                return d.getFullYear() + '-' + d.getMonth();  
            }  
        }// 配置formatter,只返回年月  
    });  
    var p = $('#'+id).datebox('panel'), // 日期选择对象  
    tds = false, // 日期选择对象中月份  
    span = p.find('span.calendar-text'); // 显示月份层的触发控件
}java

/***
 * 生成列头部分
 */
$(document).ready(function () {
    formartDate('d4311');
    formartDate('d4312');
});jquery

相关文章
相关标签/搜索