我的前端有问题。无论我从下拉列表中选择哪一年,所选年份都会以某种方式设置为2015年。任何猜测如何解决这个问题?花了差不多2小时盯着这段代码,我现在真的不知道。
<div id="tabs-4">
<div class="input-container" style="padding: 0;">
<div class="input">
<div class="controls" style="float: left;">
<form name="week" id="weekForm" action="${rootContext}/kpi/weekly" method="GET" >
<div>
Year:<br> <select name="year" id="weeklyYearForm">
<c:forEach var="i" begin="2012" end="2020">
<option value="<c:out value="${i}"/>"
${i == yearForWeek ? 'selected' : ''}>
<c:out value="${i}" />
</option>
</c:forEach>
</select>
</div>
<div>
Week:<br> <select name="week" id="weeklyWeekForm">
<c:forEach var="i" begin="1" end="53">
<option value="<c:out value="${i}"/>"
${i == weekForWeek ? 'selected' : ''}>
<c:out value="${i}" />
</option>
</c:forEach>
</select>
</div>
<div>
<input type="submit" id="runWeekly" value="Run"
class="genericSubmitButton" onclick="" name="action">
</div>
</form>
</div>
<div class="controls" style="float: right">
<form name="week" action="${rootContext}/kpi/recalculateWeek" method="GET" id="recalculateWeekForm">
<input type="text" name="year" value="${yearForWeek}">
<input type="text" name="week" value="${weekForWeek}"> <input
type="submit" id="Recalc" value="Recalculate KPI"
class="genericSubmitButton" onclick="">
</form>
<form name="week" action="${rootContext}/kpi/downloadKpiByWeek" method="GET">
<input type="hidden" name="year" value="${yearForWeek}">
<input type="hidden" name="week" value="${weekForWeek}"> <input
type="submit" id="OK" value="Export" class="genericSubmitButton"
onclick="">
</form>
</div>
</div>
</div>
<div id="dataContainerForAjaxWeekly">
<%@ include file="kpireporttable.jsp"%>
<!-- This will be updated automatically with Ajax -->
</div>
答案 0 :(得分:1)
事实证明,外部JavaScript文件正在控制下拉菜单的行为,以便选择年份&#39;它缺少控制选择的方法。下面的Js方法解决了我的问题。
$('#weeklyYearForm').change(function() {
selectedyear = $("#weeklyYearForm option:selected").val();
$('input[name=year]').val(selectedyear);
});