java - JSP 下拉列表的选定值

标签 java jsp

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

相关文章:

java - 如何在一项 Activity 中使用 Edittext 值重命名按钮?

jsp - 使用外部 Jar 文件网络应用程序/Stratos Live

java - jquery datatables-一个数据表中的最大列数

java - Tomcat是否为每个用户创建一个线程?

java - 在 JSP 中将 xml 选择转换为数字

java - 通用 getter 方法

java - 管理文件java上的大数组

java - 简单的 Java 列表问题

java - 如何在jsp页面中添加一个递增的id

java - 如何检查用户名是否已存在于我的 firebase 数据库中?