标題問題的答案在OSChina中
我還是把這個記錄下來
=================================================================
<input id="dlgReleaseTime" class="easyui-datebox"></input>
$('#dlgReleaseTime').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); //月份
$('#dlgReleaseTime').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) { return d.getFullYear() + '-' + (d.getMonth() + 1); }//配置formatter,隻傳回年月
});
var p = $('#dlgReleaseTime').datebox('panel'), //日期選擇對象
tds = false, //日期選擇對象中月份
span = p.find('span.calendar-text'); //顯示月份層的觸發控件
var curr_time = new Date();
$("#dlgReleaseTime").datebox("setValue", myformatter(curr_time));
View Code