我有一个这样的html表:
<table id="mytable" class="table table-striped">
<tbody>
<c:forEach items="${listeCollabDeRrh}" var="collab">
<tr>
<td>${collab.matricule }</td>
<td>${collab.nom }</td>
<td>${collab.prenom}</td>
<td hidden="true">${collab.bu.getNomBU()}</td>
<td hidden="true">${collab.contact}</td>
<td hidden="true">${collab.dateEmbauche}</td>
<td>
<p data-placement="top" data-toggle="tooltip" title="Details">
<button class="btn btn-primary btn-xs" data-title="Details" data-toggle="modal" data-target="#Details"> <span class="glyphicon glyphicon-text-color"></span>
</button>
</p>
</td>
</tr>
</c:forEach>
</tbody>
</table>
如果单击“详细信息”按钮,我将弹出包含行所有详细信息的弹出窗口:
<div class="modal-body">
<table id="mytable" class="table table-bordred table-striped">
<thead>
<th>Matricule</th>
<th>Nom</th>
<th>Pronom</th>
<th>BU</th>
<th>Contact</th>
<th>Date d'ambauche</th>
<th>RRH</th>
</thead>
<tbody>
<tr>
<td>matricule of collab</td>
<td>nom of collab</td>
<td>prenom of collab</td>
<td>bu of collab</td>
<td>contact of collab</td>
<td>dateEmbauche of collab</td>
</tr>
</tbody>
</table>
问题在于HTML表和详细信息弹出窗口在同一jsp页面中。我认为我可以在服务器端使用带有表单的控制器。
当我按一行的详细信息按钮时,如何显示详细信息弹出窗口?
最佳答案
$(document).ready(function(){
$(".detail_button").on("click",function(){
var parentTr = $(this).closest("tr");
var counter = 1;
$("td", $(parentTr)).each(function(){
if(!($(this).hasClass("detail_td"))){
$(".modal-body tr td:nth-child("+counter+")").text($(this).text());
counter++;
}
$(".modal-body").show();
$("#bodytable").hide();
});
});
$("#hide_popup").on("click",function(){
$(".modal-body").hide();
$("#bodytable").show();
});
});
.modal-body{
display:none;
position:absolute;
top:0;
left:0px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<div class="modal-body">
<input type="button" id="hide_popup" value="Hide Popup"/>
<div style="clear"></div>
<table id="mytable" class="table table-bordred table-striped" border="1">
<thead>
<th>Matricule</th>
<th>Nom</th>
<th>Pronom</th>
<th>BU</th>
<th>Contact</th>
<th>Date d'ambauche</th>
<th>RRH</th>
</thead>
<tbody>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
</div>
<table id="bodytable" class="table table-bordred table-striped" border="1">
<thead>
<th>Matricule</th>
<th>Nom</th>
<th>Pronom</th>
<th>BU</th>
<th>Contact</th>
<th>Date d'ambauche</th>
<th>RRH</th>
<th>Detail</th>
</thead>
<tbody>
<tr>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1</td>
<td class="detail_td">
<p data-placement="top" data-toggle="tooltip" title="Details">
<button class="detail_button btn btn-primary btn-xs" data-title="Details" data-toggle="modal" data-target="#Details"> <span class="glyphicon glyphicon-text-color">Detail</span>
</button>
</p>
</td>
</tr>
<tr>
<td>2</td>
<td>2</td>
<td>2</td>
<td>2</td>
<td>2</td>
<td>2</td>
<td>2</td>
<td class="detail_td">
<p data-placement="top" data-toggle="tooltip" title="Details">
<button class="detail_button btn btn-primary btn-xs" data-title="Details" data-toggle="modal" data-target="#Details"> <span class="glyphicon glyphicon-text-color">Detail</span>
</button>
</p>
</td>
</tr>
</tbody>
</table>
据我了解,您想在详细信息按钮单击时在弹出窗口中显示相关的行数据。如果没有,请纠正我
的HTML
<div class="modal-body">
<input type="button" id="hide_popup" value="Hide Popup"/>
<div style="clear"></div>
<table id="mytable" class="table table-bordred table-striped" border="1">
<thead>
<th>Matricule</th>
<th>Nom</th>
<th>Pronom</th>
<th>BU</th>
<th>Contact</th>
<th>Date d'ambauche</th>
<th>RRH</th>
</thead>
<tbody>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
</div>
<table id="bodytable" class="table table-bordred table-striped" border="1">
<thead>
<th>Matricule</th>
<th>Nom</th>
<th>Pronom</th>
<th>BU</th>
<th>Contact</th>
<th>Date d'ambauche</th>
<th>RRH</th>
<th>Detail</th>
</thead>
<tbody>
<tr>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1</td>
<td class="detail_td">
<p data-placement="top" data-toggle="tooltip" title="Details">
<button class="detail_button btn btn-primary btn-xs" data-title="Details" data-toggle="modal" data-target="#Details"> <span class="glyphicon glyphicon-text-color">Detail</span>
</button>
</p>
</td>
</tr>
<tr>
<td>2</td>
<td>2</td>
<td>2</td>
<td>2</td>
<td>2</td>
<td>2</td>
<td>2</td>
<td class="detail_td">
<p data-placement="top" data-toggle="tooltip" title="Details">
<button class="detail_button btn btn-primary btn-xs" data-title="Details" data-toggle="modal" data-target="#Details"> <span class="glyphicon glyphicon-text-color">Detail</span>
</button>
</p>
</td>
</tr>
</tbody>
</table>
JQUERY
$(document).ready(function(){
$(".detail_button").on("click",function(){
var parentTr = $(this).closest("tr");
var counter = 1;
$("td", $(parentTr)).each(function(){
if(!($(this).hasClass("detail_td"))){
$(".modal-body tr td:nth-child("+counter+")").text($(this).text());
counter++;
}
$(".modal-body").show();
$("#bodytable").hide();
});
});
$("#hide_popup").on("click",function(){
$(".modal-body").hide();
$("#bodytable").show();
});
});
的CSS
.modal-body{
display:none;
position:absolute;
top:0;
left:0px;
}
演示:https://jsfiddle.net/daf2rLvh/3/
关于javascript - 显示一个包含html表中每一行的详细信息的弹出窗口,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32307020/