通过响应按钮单击更改表标题,其中行使用 JSTL for 循环更新
Change table header with response to button click ,where rows update using JSTL for loop
<div class="btn-group" >
<button type="submit" onclick="display">DISPLAY SCHEDULE</button>
<button type="submit" onclick="open" >OPEN SCHEDULE</button>
</div>
<table class="table table-striped responsive">
<!-- column headers -->
<% Result result = (Result)request.getAttribute("result");%>
<thead>
<tr>
<th id="change"> Transfer Switch </th>
</tr>
</thead>
<!-- column data -->
<tbody>
<c:forEach var="row" items="${result.rows}">
<tr>
<td>
<c:out value="${row.Schedule_ID}"/>
</td>
</tr>
</c:forEach>
</tbody>
</table>
我正在尝试通过单击按钮更改我的表头名称,所以我所做的是添加一个简单的 java 脚本,如下所示。
<script>
function display(){
document.getElementById("change").innerHTML="display"
}
function open(){
document.getElementById("change").innerHTML="open"
}
</script>
但是由于我的 JSTL 结果行在每个循环中都会更新,我的标头也发生了变化,因此以相同的标头Transfer switch
结束了自己。我可以在加载时使用 Jquery 解决这个问题吗??,不确定如何使用它。
听说过制作 2 张桌子的解决方案,但这不是我正在寻找的解决方案,因为该表是响应式的,使用引导程序并且其行中也有一些按钮。
我从你的代码中更改了两件事,现在看起来不错,
不要使用 JS 保留关键字,如
open
。请改用openSchedule()
。为了更好地练习,请使用
span
标记更改文本,而不是将 id 提供给th
。
带有呈现的表行的 HTML(假设我无法在此处重现 jsp 值。
<div class="btn-group" >
<button type="button" onclick="displaySchedule()">DISPLAY SCHEDULE</button>
<button type="button" onclick="openSchedule()" >OPEN SCHEDULE</button>
</div>
<table class="table table-striped responsive">
<thead>
<tr>
<th><span id="change">Transfer Switch</span></th>
</tr>
</thead>
<tbody>
<!-- Here I assumed two rows, since It's JSP value I couldn't reproduce -->
<tr>
<td>Text1</td>
</tr>
<tr>
<td>Text2</td>
</tr>
</tbody>
</table>
你的脚本,
window.displaySchedule = function(){
document.getElementById("change").innerHTML="display";
}
window.openSchedule = function(){
document.getElementById("change").innerHTML="open";
}
在此处查看小提琴演示以获取实时样本。
相关文章:
- Javascript循环不会自我更新
- 添加文字和评论功能更新Div
- AngularJS:ng之后,重复$scope值未按预期更新
- 如何通过数组更新角度子范围
- Ajax聊天消息重复而不仅仅是更新
- 通过CSV文件上载更新数据库表
- 平均值:无法将数据更新到数据库
- $rootScope未使用forEach进行更新
- d3基于用户选择动态更新节点
- 有条件更新d3.js力图中节点的最佳方法
- Angular:更新一次性绑定的数据
- Javascript更新孙窗口中的表单元素
- 使用AngularJS中的筛选器更新给定的表
- 从选项页面更新chrome扩展清单权限
- 如何在不刷新页面的情况下更新显示框
- 延期承诺值未更新/解析/延期
- 标记的实时更新,无需加载页面谷歌地图API V3
- 使用mongodb更新中的一个变量
- 访问jsrender模板中的全局javascript变量并更新它
- 通过响应按钮单击更改表标题,其中行使用 JSTL for 循环更新