这是我的 JSP 代码:
<%if (session.getAttribute("user").toString().equalsIgnoreCase("Chhattisgarh")){ %>
<select name="district" id="district" onchange="this.form.submit()">
<c:forEach var="row" items="${result.rows}">
<option value="${row.UserDispName_Eng}">${row.UserDispName_Eng}</option>
</c:forEach>
</select>
<%} else{
out.println(session.getAttribute("user"));
} %>
我需要根据此下拉列表中的选择加载另一个下拉列表。 我看到了类似的帖子,但它对我不起作用。 How to keep Dropdownlist value same after refresh the page
我应该做什么来实现这个目标。
最佳答案
你可以做一件事。选择任何选项时,都会调用您创建的一个 Java 脚本函数。编写一段代码,在其中创建一个新的下拉 html,并在其中设置条件,根据您选择的第一个选项设置正确的选项。
onchange="callAnotherDropDown();"
Javascript
function callAnotherDropDown(){
html code.
creation of new drop down.
condition to select the proper value.
}
关于java - 如何在 JSP 中保留下拉列表的选定值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19433858/