我需要做类似的事情 /image/BHyyx.png ,但是我怎样才能用 spring 的标签做到这一点呢?我可以在 form:select
或 form:option
中输入一个复选框吗?
最佳答案
如果我们使用JSTL
并创建它所需的html
,我们就可以做到这一点。使用 bootstrap.js
和 bootstrap.css
。我们可以从互联网上下载它们并添加到我们的 Spring 项目中。
示例在这里。
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
//import bootstrap js and css
<script src="../js/bootstrap/bootstrap.js" type="text/javascript"></script>
<link href="../themes/bootstrap/bootstrap.css" rel="stylesheet" type="text/css" />
//your form goes here
<form id="searchform" method="get" action="">
<div align="center">
<div class="input-group">
<div class="input-group-btn">
<button tabindex="-1" class="btn btn-default" type="button">Select
Designation :</button>
<button tabindex="-1" data-toggle="dropdown"
class="btn btn-default dropdown-toggle" type="button">
<span class="caret"></span>
</button>
<ul role="menu" class="dropdown-menu" style="vertical-align: top;">
<li style="vertical-align: top;"> <input id="all" name="all" type="checkbox" style="width:30px;height:auto;cursor: pointer;"><label
style="vertical-align: middle;width:100%;cursor: pointer;;" for="all" > All</label>
</li>
<li class="divider"></li>
<c:forEach items="${designationList}" var="d" varStatus="status">
<li style="vertical-align: top;"><input id="${d.id}" name="${d.id}" type="checkbox" style="width:30px;height:auto;cursor: pointer;"> <label
for="${d.id}" class="lbl" style="color: #489D1F;vertical-align: middle;width:100%;cursor: pointer;"> ${d.designation}</label>
</li>
</c:forEach>
</ul>
</div>
</div>
</form>
免责声明: 我不知道使用 Spring 标签是否可以实现同样的效果,但我只是知道这种方式,所以我与你分享。可能有人知道并会发布更好的答案。但在我们找到正确的 Spring 标签方法之前,这种方法可能会对您有所帮助。
关于html - 如何使用 Spring MVC 制作带有复选框的下拉列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25485386/