我有一个基于Spring Web模型 - 视图 - 控制器(MVC)框架的项目。 Spring Web模型 - 视图 - 控制器(MVC)框架的版本是3.2.8 我在JSP中有这段代码
<div class="col-md-12" id="secondSignatoryDivId" >
<table width="100%">
<thead>
<tr>
<th><b>First name</b></th>
<th><b>Last name</b></th>
<th><b>Position</b></th>
<th><b>Title</b></th>
<th><b>Actions</b></th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="text" value="${deviceForm.device.secondSignatory.firstname}" <c:if test="${readonly}">disabled="disabled"</c:if> class="form-control"/></td>
<td><input type="text" value="${deviceForm.device.secondSignatory.lastname}" <c:if test="${readonly}">disabled="disabled"</c:if> class="form-control"/></td>
<td><input type="text" value="${deviceForm.device.secondSignatory.position}" <c:if test="${readonly}">disabled="disabled"</c:if> class="form-control"/></td>
<td><input type="text" value="${deviceForm.device.secondSignatory.title}" <c:if test="${readonly}">disabled="disabled"</c:if> class="form-control"/></td>
<td>Delete</td>
</tr>
</tbody>
</table>
</div>
<c:if test="${empty applicationForm.application.secondSignatory}">
<script>
alert ('lalalal');
$('#secondSignatoryDivId').hide();
</script>
</c:if>
我看到警报但div没有隐藏!
答案 0 :(得分:1)
您正在使用jQuery,您应该在您的html文件中包含jQuery:
alert('lalalal');
$('#secondSignatoryDivId').hide();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="col-md-12" id="secondSignatoryDivId">
<table width="100%">
<thead>
<tr>
<th><b>First name</b>
</th>
<th><b>Last name</b>
</th>
<th><b>Position</b>
</th>
<th><b>Title</b>
</th>
<th><b>Actions</b>
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<input type="text" value="${deviceForm.device.secondSignatory.firstname}" <c:if test="${readonly}">disabled="disabled"</c:if>class="form-control"/></td>
<td>
<input type="text" value="${deviceForm.device.secondSignatory.lastname}" <c:if test="${readonly}">disabled="disabled"</c:if>class="form-control"/></td>
<td>
<input type="text" value="${deviceForm.device.secondSignatory.position}" <c:if test="${readonly}">disabled="disabled"</c:if>class="form-control"/></td>
<td>
<input type="text" value="${deviceForm.device.secondSignatory.title}" <c:if test="${readonly}">disabled="disabled"</c:if>class="form-control"/></td>
<td>Delete</td>
</tr>
</tbody>
</table>
</div>
答案 1 :(得分:0)
如果只是隐藏元素,那么最好使用 css :
<c:if test="${empty applicationForm.application.secondSignatory}">
<style>
#secondSignatoryDivId.col-md-12 { display:none; }
</style>
</c:if>