struts2的jsp页面的table每行显示四个td应该怎么写代码?

我在某table里用<s:iterator>显示某List的内容,想每行显示四个td,写了如下代码:

<s:if test="!(#st.index % 4)"><tr></s:if>
某些td代码
<s:if test="!(#st.index % 4)"></tr></s:if>

结果显示错乱,有的行显示一个td,有的显示3个。怎么才能按照我的想法显示?

阅读 3.5k
3 个回答

问题解决了,应该在<s:iterator>和</s:iterator>标签之间放入:

        <s:if test="(#st.index % 4) == 0 && (#st.index != 0)">
            </tr>
            <tr>
        </s:if>
        <s:elseif test="#st.index == 0">
            <tr>
        </s:elseif>

这样不行吗

<s:iterator value="#list" id="obj">
    <tr>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
    </tr>
</s:iterator>
<s:iterator>
        <s:if test="(#st.index % 4) == 0 && (#st.index != 0)">
            </tr>
            <tr>
        </s:if>
        <s:elseif test="#st.index == 0">
            <tr>
        </s:elseif>
</s:iterator>
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题