使用javascript

时间:2017-07-28 06:53:06

标签: javascript jsp jstl

我有一个带有JSTL标签的jsp页面.jsp页面包含2个不同的标签。如果用户单击第一个标签,那么想要显示一个包含tbody的表包含值列表。这样可以正常工作。现在我想要更改c:当用户单击第二个选项卡时,每个项目。两个选项卡列表包含具有不同值的相同参数。所以我需要使用javascript更改c:forEach的项目。这可能吗 ?

感谢你

在jsp中

<table id="dynamic-table">
<thead>
<tr>
<th>Sl.No.</th>
<th class="sorting_disabled">Loan Id</th>
<th class="sorting_disabled">Name</th>
</tr>
</thead>
<tbody> 
<c:forEach var="mainlist" items="${S1List}" varStatus="status">
<tr>
<td class="center">${status.index + 1}</td>
<td>${mainlist.loanId}</td>
<td>${mainlist.name}</td>
</tr>
</tbody>
</table>

我想使用javascript将items =“$ {S1List}”更改为items =“$ {S2List}”

的Javascript

funcion changevalueWhenSecondTabclick(){
//I want the solution code here
}

1 个答案:

答案 0 :(得分:1)

您可以使用Jquery实现此目的。您应该将S2List存储在jquery变量中。在我看来,我将实现如下

$(document).ready(function() {
  //This part let's you to store the list in Java script variable
  var list2ObjectValue="${S2List}";

  funcion changevalueWhenSecondTabclick(){
     //I want the solution code here
     $('#dynamic-table tbody').empty();
     $.each( list2ObjectValue, function( index, value ){
        $('#dynamic-table').append('<tr>'
               +'<td class="center">' + index + '</td>'
               +'<td>' + value.loanId + '</td>'
               +'<td>' + value.name + '</td>'
               +'</tr>');
   });
  }
});

单击第一个标签时尝试相同的方法。

相关问题