我有一个函数,我想获取今天日期的周数,但无法在单击按钮时在文本框中打印值。我是 javascript 新手,我已经调试了好几个星期了。请帮忙
function getWeekNumber(d) {
d = new Date(Date.UTC(d.getFullYear(), d.getMonth(), d.getDate()));
d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay()||7));
var yearStart = new Date(Date.UTC(d.getUTCFullYear(),0,1));
var weekNo = Math.ceil(( ( (d - yearStart) / 86400000) + 1)/7);
return [d.getUTCFullYear(), weekNo];
document.getElementById("week").value = getWeekNumber(new Date());
}
<td>WEEK: </td>
<td><input type="text" value= "" style= "width: 230px; padding-left: 3px" id="week" name="week"></td>
<input type="button" value="Get Week" onclick= "getWeekNumber()">
GCT1015
相关分类