在我目前的春季项目中,我有一个包含此内容的jsp页面:
<c:url value="/${command['class'].simpleName}/index" var="index"/>
<button type="button" class="btn btn-default action" data-url="${index}">Voltar</button>
<c:url value="/${command['class'].simpleName}/delete" var="remove"/>
<form class="form" role="form" method="post" action="${remove}">
<input type="hidden" name="id" value="${command.id}"/>
<div class="panel panel-default pergunta">
<div class="panel-heading">Remoção</div>
<div class="panel-body">
<p>Confirma remoção do registro abaixo?</p>
</div>
<ul class="list-group">
<c:forEach var="item" items="${command['class'].declaredFields}">
<c:set var="field" value="${item.name}"/>
<c:if test="${field != 'role' && field != 'permission'}">
<li class="list-group-item"><strong>${item.name}</strong>: ${command[item.name]}</li>
</c:if>
</c:forEach>
</ul>
<div class="panel-footer">
<button type="submit" class="btn btn-lg btn-link" id="sim">Sim</button>
<button type="button" class="btn btn-lg btn-link" id="nao">Não</button>
</div>
</div>
</form>
<div class="alert alert-success alert-dismissible" id="yes" role="alert" style="display: none;">
<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
Registro removido com sucesso.
</div>
<div class="alert alert-danger alert-dismissible" id="not" role="alert" style="display: none;">
<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<span class="text"></span>
</div>
按钮(class="btn btn-default"
)中的点击次数由此jquery代码处理:
$(document).ready(function(){
$(document).on("submit", "form.form", function (event) {
event.preventDefault();
var $form = $( this ), url = $form.attr( "action" );
var posting = $.post( url, $(this).serialize() );
posting.done(function( data ) {
$("div.pergunta").hide();
if(data == "") {
$("#yes").show();
} else {
var $temp = $('<div/>', {html:data});
$("#not").find(".text").html( $temp.remove('head').html() );
$("#not").show();
}
});
});
$(document).on("click", "button.action", function(event){
event.preventDefault();
var url = $(this).data("url");
$.get(url, function(data){
var target = $("div.panel-default");
var $temp = $('<div/>', {html:data});
target.empty();
target.html( $temp.remove('head').html() );
});
});
$(document).on("click", "#nao", function(event){
event.preventDefault();
$("div.pergunta").hide();
});
});
但指令$("div.pergunta").hide()
无效。
上面的页面已添加到此页面的<div>
内,其中包含课程panel panel-default
:
<div class="panel panel-default">
<div class="panel-heading">${command['class'].simpleName}</div>
<div class="panel-body">
<c:url value="/${command['class'].simpleName}/cadastra" var="cadastrar"/>
<div align="left"> <button type="button" class="btn btn-default action" data-url="${cadastrar}">cadastrar</button> </div>
</div>
<table class="table">
<thead>
<tr>
<th></th>
<c:forEach var="item" items="${command['class'].declaredFields}">
<c:set var="field" value="${item.name}"/>
<c:if test="${field != 'role' && field != 'permission'}">
<th>${item.name}</th>
</c:if>
</c:forEach>
<th></th>
</tr>
</thead>
<tbody>
<c:forEach var="item" items="${lista}">
<tr>
<td></td>
<c:forEach var="item2" items="${command['class'].declaredFields}">
<c:set var="field" value="${item2.name}"/>
<c:if test="${field != 'role' && field != 'permission'}">
<td>${item[field]}</td>
</c:if>
</c:forEach>
<td>
<div class="btn-group">
<c:url value="/${command['class'].simpleName}/altera" var="alterar"/>
<button type="button" class="btn btn-default action" data-url="${alterar}/${item.id}">alterar</button>
<c:url value="/${command['class'].simpleName}/remove" var="remover"/>
<button type="button" class="btn btn-default action" data-url="${remover}/${item.id}">remover</button>
</div>
</td>
</tr>
</c:forEach>
</tbody>
</table>
</div>
<script>
$(document).ready(function(){
$(document).on("click", "button.action", function(event){
event.preventDefault();
var url = $(this).data("url");
$.get(url, function(data){
var target = $("div.panel-default");
var $temp = $('<div/>', {html:data});
target.empty();
target.html( $temp.remove('head').html() );
});
});
});
</script>
任何人都可以提示如何使此代码与div.pergunta
一起使用?
答案 0 :(得分:1)
尝试给出一个&#34; id&#34;到那个div,然后使用
$('#something_id').hide();