当我执行此代码时,警报显示为'undefined'而不是当前月份的值
function jump() {
selectYear = document.getElementById("start"); // used for jump section
selectYear = selectYear.value.toString().slice(0,4);
selectMonth = document.getElementById("start"); // used for jump section
selectMonth = selectMonth.value.toString().slice(5,7);
currentYear = selectYear.value;
currentMonth = selectMonth.value;
alert (currentMonth);
window.value = 0;
showCalendar(currentMonth, currentYear);
}
答案 0 :(得分:0)
如注释中所述,您需要将其从字符串解析为整数。 selectMonth
是一个字符串,因此没有.value
助手。
您可以使用parseInt()
函数来解决此问题,而不是使用.value
帮助器。
答案 1 :(得分:0)
function jump() {
selectYear = document.getElementById("start").value;
selectYear = selectYear.value.toString().slice(0,4);
selectMonth = document.getElementById("start").value;
selectMonth = selectMonth.value.toString().slice(5,7);
currentYear = selectYear.value;
currentMonth = selectMonth.value;
alert (currentMonth);
window.value = 0;
showCalendar(currentMonth, currentYear);
}