利用jQuery实现datepicker只显示年,月,不显示日 year,month only

时间:2024-02-24 22:43:50

思路:利用jquery的close函数,利用fiefox寻找日期的div块,利用css知识将其隐藏

以下是代码部分

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
  <link   href="css/ui-lightness/jquery-ui-1.7.2.custom.css" type="text/css" rel="Stylesheet"/>
      <script type="text/javascript" src="js/jquery-1.3.2-vsdoc.js"></script>
     <script type="text/javascript" src="js/jquery-ui-1.7.2.custom.min.js"></script>
     <script type="text/javascript"  src="js/Datepicer-zh-CN.js"></script>//中文汉化
 
 
     <script type="text/javascript">
         $(function() {
         $(\'#Datepicker\').datepicker({
                 changeMonth: true,
                 changeYear: true,
                 dateFormat: \'yy-MM\',
                 showButtonPanel: true,
                 onClose: function(dateText, inst) {
                     var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
                     var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
                     $(this).datepicker(\'setDate\', year+\'-\'+month);
                 }
             });
         });           
</script>

<style type="text/css">

.ui-datepicker-calendar {
    display: none;
    }

    </style>
</head>
<body>
    <form id="form1" runat="server">
          Date:  <input  id="Datepicker" type="text"/>
    </form>
</body>
</html>