<!--实现小时-->
<select id="hour" name="hour">
<s:bean name="org.apache.struts2.util.Counter" id="counter">
<s:param name="first" value="0" />
<s:param name="last" value="23" />
<s:iterator>
<s:if test="hour == current-1"><option selected="selected"><s:property value="current-1"/></option></s:if>
<s:else><option><s:property value="current-1"/></option></s:else>
</s:iterator>
</s:bean>
</select>:
<!--实现分钟-->
<select id="minute" name="minute">
<s:bean name="org.apache.struts2.util.Counter" id="counter">
<s:param name="first" value="0" />
<s:param name="last" value="59" />
<s:iterator>
<s:if test="minute == current-1"><option selected="selected"><s:property value="current-1"/></option></s:if>
<s:else><option><s:property value="current-1"/></option></s:else>
</s:iterator>
</s:bean>
</select>
注:first属性指定循环起始值,last指定循环终止值,在下面迭代器中输入循环的当前值 current
本文介绍如何使用 Struts2 框架中的 Counter 组件和迭代器来实现一个时间选择器,该选择器可以自动生成小时和分钟的下拉选项,并支持预设当前时间。
289

被折叠的 条评论
为什么被折叠?



