javascript - how to remove class if array list is empty inside jsp page? - Stack Overflow

i have following code i want to remove tbl-content class if recordList array is empty<table id="

i have following code i want to remove tbl-content class if recordList array is empty

<table id="gradient-style">
 <tbody class="tbl-content">
  <tr>
         <%
            for (RecordBean record : recordList) {
           // some code here to get result      
         }              
        %>
        <%
            if (recordList.isEmpty()) 
          {
        %>            
            <tr>
               <td colspan="12" align="center" style="color: red;font-family: verdana"> 
                  <h3>No Search records </h3>
              </td>
           </tr>
            <%      
               }
            %>
       </tbody>
   </table>

here is css

 .tbl-content{   
     height: 650px;;
     overflow: auto;
     position: absolute;
     border: 1px solid gray;
     border-top: none;  
     }

i have following code i want to remove tbl-content class if recordList array is empty

<table id="gradient-style">
 <tbody class="tbl-content">
  <tr>
         <%
            for (RecordBean record : recordList) {
           // some code here to get result      
         }              
        %>
        <%
            if (recordList.isEmpty()) 
          {
        %>            
            <tr>
               <td colspan="12" align="center" style="color: red;font-family: verdana"> 
                  <h3>No Search records </h3>
              </td>
           </tr>
            <%      
               }
            %>
       </tbody>
   </table>

here is css

 .tbl-content{   
     height: 650px;;
     overflow: auto;
     position: absolute;
     border: 1px solid gray;
     border-top: none;  
     }
Share Improve this question asked Sep 27, 2013 at 11:47 Developer DeskDeveloper Desk 2,3449 gold badges42 silver badges78 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 5

Try this server side inline code

<tbody class="<%= recordList.isEmpty()?"":"tbl-content" %>">

You can write JSTL code directly in script tag.

 <script>    
<c:if test="${empty recordList}">
//write code here to remove class
</c:if>
</script>

Use Java Expression Language. Its not good practice to use Java Scriptlet. Also you want to be careful not to use JSTL with JavaScript its a mix of concern.

<tbody class=" ${empty recordList ? '' : 'tbl-content' }" >

do it this way:

<table id="gradient-style">
 <tbody
<%
            if (!recordList.isEmpty()) 
          {
        %> 
class="tbl-content"
 <%      
               }
            %>
>
  <tr>
         <%
            for (RecordBean record : recordList) {
           // some code here to get result      
         }              
        %>
        <%
            if (recordList.isEmpty()) 
          {
        %>            
            <tr>
               <td colspan="12" align="center" style="color: red;font-family: verdana"> 
                  <h3>No Search records </h3>
              </td>
           </tr>
            <%      
               }
            %>
       </tbody>
   </table>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744992688a4605000.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信