利用jQuery實現datepicker只顯示年,月,不顯示日 year,month only
思路:利用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>