<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>更改easyui日期控件,使其只显示到年月</title> <!-- 引入jquery脚本文件,jquery必须在easyui之前引入,因为easyui是jquery的插件 --> <script type="text/javascript" src="js/jquery-easyui-1.3.6/jquery-1.8.0.min.js"></script> <!-- 引入easyui脚本文件 --> <script type="text/javascript" src="js/jquery-easyui-1.3.6/jquery.easyui.min.js"></script> <!-- 引入easyui样式文件 --> <link rel="stylesheet" type="text/css" href="js/jquery-easyui-1.3.6/themes/default/easyui.css"> </head> <body> <input id="myDate" name="myDate" class="easyui-datebox" data-options="formatter:myFormatter,parser:myParser"></input> </body> <script type="text/javascript"> function myFormatter(date){ var y = date.getFullYear(); var m = date.getMonth()+1; return y+'-'+(m<10?('0'+m):m); } function myParser(s){ if(!s){ return new Date(); } var ss = s.split('-'); var y = parseInt(ss[0],10); var m = parseInt(ss[1],10); if (!isNaN(y) && !isNaN(m)){ return new Date(y,m-1); } } $(document).ready(function(){ if(!$("#myDate").datebox('getValue')){$("#myDate").datebox('setValue',myFormatter(new Date())); } }); </script> </html>
转载于:https://www.cnblogs.com/iamconan/p/7383558.html
转载请注明原文地址: https://mac.8miu.com/read-3638.html