【问题标题】:I want to display the values in Table td based on IF condtions我想根据 IF 条件显示 Table td 中的值
【发布时间】:2015-11-21 20:05:13
【问题描述】:

我想以这样的方式打印表格中的值。<br> 表中有两个<td>。基于<if> 条件<td> 必须显示值。
这应该是有序的,我的意思是不应该有空白值,例如
(if i==1) 然后第一个 td 将变为空白并打印 2 个 td。
(if i==2) 然后第一个 td 将显示和 2 个 td将变为空白。
每个有价值的人都应该一个接一个地打印,没有空白。

<table>
<%
   for(int i=0;i<=5;i++){ %>
     <tr> 
        <% if((i==2) || (i==4){  %>
            <td> only this 1st <td> get printed </td>    
        <%   } else {   %>
           <td> only this 2nd <td> get printed </td>
  <% }     
} 
 %>

【问题讨论】:

标签: javascript php css html


【解决方案1】:
<table>
<%
   for(int i=0;i<=5;i++){ %>
     <tr> 
        <% if((i=2) || (i==4){  %>
            <td> only this 1st <td> get printed </td>    
        <%   } else {   %>
           <td> only this 2nd <td> get printed </td>
  <% }     
} 
 %>

只有您的第一个 td 被打印,因为在您的 IF 条件下,您没有将 $i 与值 2 进行比较,而是分配了 $i=2,因此将 if(($i=2) || ($i==4)) 更改为 if(($i==2) || ($i==4)) 并将干得好。

希望这对您的问题有所帮助

【讨论】:

    猜你喜欢
    • 2014-06-21
    • 1970-01-01
    • 1970-01-01
    • 2023-02-10
    • 1970-01-01
    • 2021-04-19
    • 1970-01-01
    • 2023-03-29
    • 1970-01-01
    相关资源
    最近更新 更多