var func1=function(y,w){ return new Date(y,0,(w-1)*7+1); }; var func2=function(y,w){ return new Date(y,0,w*7); }; alert(func1(2012,4)); alert(func2(2012,4));
解决方法: 年份那可以自己加几个比如2010,2009,2008等等<asp:DropDownList ID="DropDownList1" runat="server" onchange="addOption()"> </asp:DropDownList> <asp:DropDownList ID="DropDownList2" runat="server" onchange="getOption()"> </asp:DropDownList> JS代码: function addOption() { var obj1 = document.getElementById('DropDownList1'); var index = obj1.selectedIndex; var val = obj1.options[index].value; var obj = document.getElementById('DropDownList2'); obj.options.length = 0; for (var i = 1; i < 53; i++) { obj.options.add(new Option("第" + i + "周", setOptionDate(val, i))); } } function setOptionDate(y, w) { return new Date(y, 0, (w - 1) * 7 + 1).toLocaleDateString(); } function getOption() { var obj1 = document.getElementById('DropDownList2'); var index = obj1.selectedIndex; var val = obj1.options[index].value; alert(val); }
return new Date(y,0,(w-1)*7+1);
};
var func2=function(y,w){
return new Date(y,0,w*7);
};
alert(func1(2012,4));
alert(func2(2012,4));
年份那可以自己加几个比如2010,2009,2008等等<asp:DropDownList ID="DropDownList1" runat="server" onchange="addOption()">
</asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server" onchange="getOption()">
</asp:DropDownList>
JS代码: function addOption() {
var obj1 = document.getElementById('DropDownList1');
var index = obj1.selectedIndex;
var val = obj1.options[index].value; var obj = document.getElementById('DropDownList2');
obj.options.length = 0;
for (var i = 1; i < 53; i++) {
obj.options.add(new Option("第" + i + "周", setOptionDate(val, i)));
}
}
function setOptionDate(y, w)
{
return new Date(y, 0, (w - 1) * 7 + 1).toLocaleDateString();
}
function getOption() {
var obj1 = document.getElementById('DropDownList2');
var index = obj1.selectedIndex;
var val = obj1.options[index].value;
alert(val);
}