我使用Java 7,Struts 1.2.7,Servelt 2.4,JSP 1.2
我有一个Action adminHome.do和一个jsp页面adminHome.jsp
这是adminHome.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Admin Home</title>
</head>
<body>
<table bgcolor="white" border=0 cellpadding=2 cellspacing=2>
<html:form action="/adminHome.do" method="post">
<tr><td class="lightblue" align=right>email: </td>
<td><html:text size="40" property="email"/></td></tr>
<tr><td class="lightblue" align=right>first name: </td>
<td><html:text size="40" property="firstName"/></td></tr>
<tr><td class="lightblue" align=right>last name: </td>
<td><html:text size="40" property="lastName"/></td></tr>
<tr><td class="lightblue" align=right>user id: </td>
<td><html:text size="40" property="userId"/></td></tr>
<tr><td class="lightblue" align=right>competition: </td>
<td><html:select property="competitionId">
<c:forEach var="competition" items="${competitionsSorted}">
<html:option value="${competition.competitionId}">${competition}
</html:option>
</c:forEach>
</html:select></td></tr>
<tr><td align=center colspan=2><br/>
<html:submit property="submit" value="search"/>
</td>
</tr>
</html:form>
</table>
</body>
</html>
admin form
搜索用户示例
+-----------------+------------------------+
| Email | |
+-----------------+------------------------+
| First Name | |
+-----------------+------------------------+
| Last Name | |
+-----------------+------------------------+
| User | 123 | <- UserID = 123
+-----------------+------------------------+
| Competition | Competition 1 |
+-----------------+------------------------+
| Competition 2 |
| Competition 3 | <- drop down list
| Competition 4 |
+----------------+
在此admin form
如果userId不为空,我想要禁用竞争下拉列表。
答案 0 :(得分:2)
这可以使用普通的javascript来完成。
下面的代码应该适合你。
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Admin Home</title>
<script>
function disable()
{
document.forms[0].competitionId.disable();
}
</script>
</head>
<body>
<table bgcolor="white" border=0 cellpadding=2 cellspacing=2>
<html:form action="/adminHome.do" method="post">
<tr><td class="lightblue" align=right>email: </td>
<td><html:text size="40" property="email"/></td></tr>
<tr><td class="lightblue" align=right>first name: </td>
<td><html:text size="40" property="firstName"/></td></tr>
<tr><td class="lightblue" align=right>last name: </td>
<td><html:text size="40" property="lastName"/></td></tr>
<tr><td class="lightblue" align=right>user id: </td>
<td><html:text size="40" property="userId" onblur="disable()"/></td></tr>
<tr><td class="lightblue" align=right>competition: </td>
<td><html:select property="competitionId">
<c:forEach var="competition" items="${competitionsSorted}">
<html:option value="${competition.competitionId}">${competition}
</html:option>
</c:forEach>
</html:select></td></tr>
<tr><td align=center colspan=2><br/>
<html:submit property="submit" value="search"/>
</td>
</tr>
</html:form>
</table>
</body>
</html>
如果您有任何其他问题,请与我们联系。