0

我在 JSP 页面中有一个 Struts 1.2 Bean 和一个 Bean 代码,如下所示

复选框.jsp

<logic:iterate property="userList" id="userDet" name="userDetails">
  <html:checkbox property="checked" name="userDet" indexed="true">
   <bean:write property="userName" name="userDet"></bean:write>
  </html:checkbox>
</logic:iterate>

上面的代码带来如下输出

在此处输入图像描述

现在,当我提交表单时,我想使用复选框的 id 执行 Javascript 验证。

如何为 JSP 页面中通过 Bean 生成的复选框生成 id?是否可以动态生成 id 属性?

4

1 回答 1

1

尝试使用“indexId”属性(页面范围 JSP bean 的名称,它将包含每次迭代时集合的当前索引。)

<logic:iterate>

并在 'styleId' 属性中使用它

<html:checkbox>

像这样:

<logic:iterate property="userList" id="userDet" name="userDetails" indexId="checkBoxIndex">
  <html:checkbox property="checked" name="userDet" indexed="true" styleId="checkBox<%= checkBoxIndex %>">
   <bean:write property="userName" name="userDet"></bean:write>
  </html:checkbox>
</logic:iterate>
于 2013-05-14T14:19:15.880 回答