我使用 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 Incentive
、Advertising Incentive
和 ChannelPlacement 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。
自从您使用了 theme="simple"
,不会生成额外的标记,您需要自己处理,通过手动创建 <tr>
和 <td>
复选框周围的标签:
<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
也是属性。
关于html - Struts2 中的复选框对齐问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27483446/