【问题标题】:Checkboxes alignment issues in Struts2Struts2 中的复选框对齐问题
【发布时间】:2014-12-16 02:40:57
【问题描述】:

我使用 Struts2 复选框显示带有标题的复选框以及值,如下所示:

<table id="incentiveTable">
    <thead>
        <tr>
            <th colspan="1" style="font-size: 12px; text-align: center; padding: 7px;">     
                Marketing Incentive
            </th>
            <th colspan="1" style="font-size: 12px; text-align: center; padding: 7px;">     
                Advertizing Incentive
            </th>
            <th colspan="1" style="font-size: 12px; text-align: center; padding: 7px;">     
                ChannelPlacement Incentive
            </th>
            </tr>
    </thead>
    <tbody>
        <s:iterator status="stat" value="incentiveList">
            <s:checkbox name="checkboxes[%{#stat.marketingIncentive}]"  theme="simple" />
            <s:checkbox name="checkboxes[%{#stat.advertizingIncentive}]"  theme="simple" />
            <s:checkbox name="checkboxes[%{#stat.channelPlacementIncentive}]"  theme="simple" />
        </s:iterator>
    </tbody>
</table>

但是,复选框没有正确对齐:

我需要标题是 Marketing IncentiveAdvertizing IncentiveChannelPlacement Incentive 与复选框相邻

上面的代码我用过,但是不行

我已经将代码进一步修改为

<table id="incentiveTable">
                <thead>
                    
                </thead>
                <tbody>
                            <tr>
                                    <td>
                                            Marketing Incentive
                                    </td>
                                    <td>
                                            Advertizing Incentive
                                    </td>
                                    <td>
                                            Advertizing Incentive
                                    </td>
                            </tr>   
                        <s:iterator status="stat" value="incentiveList">
                            <tr>
                                
                                    <td>
                                    <s:checkbox name="checkboxes[%{#incentiveList.marketingIncentive}]"  theme="simple" />
                                    </td>
                                    
                                    
                                <td>
                                    <s:checkbox name="checkboxes[%{#incentiveList.advertizingIncentive}]"  theme="simple" />
                                </td>
                                
                                
                                <td>
                                    <s:checkbox name="checkboxes[%{#incentiveList.channelPlacementIncentive}]"  theme="simple" />
                                </td>
                            </tr>
                        </s:iterator>
                    
                    <s:submit id="submitButton" name="submit" value="Submit Incentives" onclick='return closeWindow()' disabled="true"/>
                    
                </tbody>
            </table>

o/p 如第二张图所示

请建议对齐方式

【问题讨论】:

    标签: html css jsp checkbox struts2


    【解决方案1】:

    您的标签生成的代码不是有效的 HTML。

    由于您使用了theme="simple",因此不会生成额外的标记,您需要自行处理,方法是在复选框周围手动创建&lt;tr&gt;&lt;td&gt; 标签:

    <tbody>
        <s:iterator status="stat" value="incentiveList">
        <tr>
            <td>
                <s:checkbox name="checkboxes[%{#stat.index}].marketingIncentive"  theme="simple" />
            </td>
            <td>
                <s:checkbox name="checkboxes[%{#stat.index}].advertizingIncentive"  theme="simple" />
            </td>
            <td>
                <s:checkbox name="checkboxes[%{#stat.index}].channelPlacementIncentive"  theme="simple" />
            </td>
        </tr>
        </s:iterator>
    </tbody>
    

    编辑:IteratorStatus 使用也存在错误,现已更正。

    为了使这个工作顺便说一句,您需要确保 checkboxes 也是源列表的名称,而不是目标列表,否则您也需要使用 value 属性。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-09
      • 2021-04-12
      • 2021-02-19
      • 1970-01-01
      • 1970-01-01
      • 2023-01-24
      • 1970-01-01
      • 2016-04-21
      相关资源
      最近更新 更多