我有兩個下拉列表持有幾個月和幾年...獲取當前的月份和日期使用jquery
$(document).ready(function() {
$('#Months option:eq(' + (new Date).getMonth() + ')').prop('selected', true);
alert((new Date).getMonth());
$('#Years option:eq(' + (new Date).getFullYear() + ')').prop('selected', true);
alert((new Date).getFullYear());
});
我寫了如上的jQuery腳本,使我的程序運行時的下拉列表中選擇值必須是當前月和年..
但是當我執行程序.. 警報給出7和2012 ..但在我看來當前的月份被選中,但當年不是爲什麼?以及如何讓我的下拉列表選擇當年?
提供一些更多的代碼,並張貼在jsfiddle.net演示 –