简体   繁体   中英

disable click and add a class to tag on basis of certain value

I want to disable click and add a class to tag on basis of certain value.

<c:forEach var="data" items="${actionBean.empList }" varStatus="loop">
  <c:set var="marks" value="${actionBean.marks}"</c:set> 
  <tr onclick="details('${ data.empId }');">
      <td>${ data.name }</td>
     <td>${ data.marks }</td>
 </tr>
</c:forEach>

on the basis of value for marks i want to disable click of tr tag and add a class to tr tag.

I want to grey out record where marks is less than say 10 and user is not able to click that now to see next page.

You can do this using the jstl <c:choose> tag like this,

<c:forEach var="data" items="${actionBean.empList }" varStatus="loop">
  <c:set var="marks" value="${actionBean.marks}"</c:set> 
  <c:choose>
    <c:when test="your condition?">
      <tr class="yourClass"></tr>
    </c:when>
    <c:otherwise>
      <tr onclick="details('${ data.empId }');"></tr>
    </c:otherwise>
  </c:choose>

</c:forEach>

In the above code, the <c:when> block will be executed if the condition is true. You can add multiple <c:when> tags if you want to add more conditions. If all <c:when> are false then by default <c:otherwise> will be executed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM