Forms 如何在JSP中禁用下拉列表?

Forms 如何在JSP中禁用下拉列表?,forms,jsp,struts,Forms,Jsp,Struts,我使用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 T

我使用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>
在此
管理表单中

如果userId不是空的,我想有一个禁用的竞争下拉列表


这可以通过普通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>

管理之家
函数禁用()
{
document.forms[0]。competitionId.disable();
}
电邮:
名字:
姓氏:
用户id:
比赛:
${竞争}


如果您还有任何问题,请告诉我。

禁用表示您不想查看下拉列表的值?这表示下拉列表应被禁用,因此我无法从该下拉列表中选择值。简而言之:好像它不存在。struts不能为您禁用它,但是您可以使用属性将其禁用。
<%@ 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>