javascript - 为什么此警报显示“未定义”而不是当前月份的值?
问题描述
当我执行此代码时,警报会显示“未定义”而不是当前月份的值
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);
}
解决方案
如评论中所述,您需要将其从字符串解析为整数。selectMonth
是一个字符串,因此它没有.value
助手。
您可以使用该parseInt()
功能来解决此问题,而不是使用.value
帮助程序。
推荐阅读
- batch-file - 执行 bat 文件后获取不需要的文件
- r - R使用嵌套的for循环尾部扩展和处理数据
- r - t.test 在第三列上的特定代码之后的两列之间
- sql - 如何在spark上做一个sql连接?
- scala - 在scala中将字符串日期(不带分隔符)转换为日期格式
- html - 我的导航栏粘在页面的右边缘,当它在滚动时粘在顶部
- php - 如何以小时、天、周、月、年 PHP 的形式获取分钟
- php - 我怎样才能改变css的特性?
- python - Python Selenium rel=nofollow 链接
- python - 如何在 QScintilla 中实现基于缩进的代码折叠?