JS和JSP实现年月日第几周下拉框选择时间
时间: 2024-05-11 19:14:53 浏览: 107
JS实现年月日第几周下拉框选择时间:
```html
<label for="year">年份:</label>
<select id="year"></select>
<label for="month">月份:</label>
<select id="month"></select>
<label for="week">第几周:</label>
<select id="week"></select>
<script>
// 获取当前年份
var currentYear = new Date().getFullYear();
// 填充年份下拉框
for (var i = currentYear; i >= 2015; i--) {
var option = document.createElement("option");
option.value = i;
option.text = i;
document.getElementById("year").add(option);
}
// 填充月份下拉框
for (var i = 1; i <= 12; i++) {
var option = document.createElement("option");
option.value = i;
option.text = i;
document.getElementById("month").add(option);
}
// 填充第几周下拉框
for (var i = 1; i <= 53; i++) {
var option = document.createElement("option");
option.value = i;
option.text = i;
document.getElementById("week").add(option);
}
</script>
```
JSP实现年月日第几周下拉框选择时间:
```html
<label for="year">年份:</label>
<select id="year">
<option value="${currentYear}">${currentYear}</option>
<c:forEach begin="2015" end="${currentYear-1}" var="year">
<option value="${year}">${year}</option>
</c:forEach>
</select>
<label for="month">月份:</label>
<select id="month">
<c:forEach begin="1" end="12" var="month">
<option value="${month}">${month}</option>
</c:forEach>
</select>
<label for="week">第几周:</label>
<select id="week">
<c:forEach begin="1" end="53" var="week">
<option value="${week}">${week}</option>
</c:forEach>
</select>
```
其中,`${currentYear}`是JSP中的EL表达式,表示获取当前年份。`<c:forEach>`是JSTL标签库中的循环标签,可以用来生成下拉框的选项。
阅读全文