gpt4 book ai didi

java - JSP 下拉菜单的选定值

转载 作者:行者123 更新时间:2023-11-30 09:03:40 24 4
gpt4 key购买 nike

在我的 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>

<-------- 在这里编辑------------>

这是我的下拉菜单的样子

enter image description here

一旦我点击“添加新”,它看起来像这样,但我想要“--请选择--”而不是“添加新”(见下图) enter image description here

在我添加“meme”之后,我的下拉菜单看起来像这样

enter image description here

但我想要这样 enter image description here

最佳答案

试试这个,如果需要,根据你的条件修改 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com