在我的 JSP 页面中,我使用弹出窗口将新沉淀剂添加到下拉列表中。它工作正常,但问题是如果我添加一个,dorpdown 显示“添加新的”而不是“--请选择--”
这是我后来尝试的
<c:if test="${listop.precipitants eq listop.precipant}">Selected </c:if>
并得到Unterminated <form:option tag
异常
这是我的 Controller 代码
map.put("precipitantdroplist", bioprofileservice.listPrecipitantdrop());
map.put("Precipitantdropfam", new Precipitantsdrop());
和 JSP 中
<form:select path="precipant" id="precipant" onchange="showpopup(this.options[this.selectedIndex].value,this.form,'Newprecipant?#login_form3');">
<form:option value="">--Please Select--</form:option>
<c:if test="${!empty precipitantdroplist}">
<c:forEach items="${precipitantdroplist}" var="listop">
<form:option value="${listop.precipitants}" <c:if test="${listop.precipitants eq listop.precipant}">Selected </c:if>>${listop.precipitants}</form:option>
</c:forEach>
</c:if>
<form:option value="">-----------------------</form:option>
<form:option value="Add New">Add New</form:option>
<form:option value="removeP">Remove</form:option>
</form:select>
<--------在此编辑---------->
这就是我的下拉菜单的样子
一旦我点击“添加新的”,它看起来像这样,但我想要“--请选择--”而不是“添加新的”(见下图)
添加“meme”后,我的下拉菜单看起来像这样
但我想要这样
最佳答案
尝试一下,如果需要,根据您的条件修改 if 条件。
<form:select name="precipant" path="precipant" id="precipant" onchange="showpopup(this.options[this.selectedIndex].value,this.form,'Newprecipant?#login_form3');">
<form:option value="" selected="selected">--Please Select--</form:option>
<c:forEach items="${precipitantdroplist}" var="listop">
<c:if test="${listop.precipitants eq listop.precipant}">
<option value="${listop.precipitants}">${listop.precipitants}</option>
</c:if>
<c:if test="${listop.precipitants != listop.precipant}">
<option value="${listop.precipitants}">${listop.precipitants}</option>
</c:if>
</c:forEach>
<form:option value="">-----------------------</form:option>
<form:option value="Add New">Add New</form:option>
<form:option value="removeP">Remove</form:option>
</form:select>
或者像这样注册下拉列表的处理程序,
<script type="text/javascript">
$(document).ready(function() {
$("#precipant").change(function() {
$('select[name^="precipant"] option:selected').attr("selected",null);
$('select[name^="precipant"] option[value="Please Select"]').attr("selected","selected");
});
});
</script>
关于java - JSP 下拉列表的选定值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25562017/