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

标签 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 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>

管理表单搜索用户示例

+-----------------+------------------------+
| Email           |                        |
+-----------------+------------------------+
| First Name      |                        |
+-----------------+------------------------+
| Last Name       |                        |
+-----------------+------------------------+ 
| User            |     123                |  <- UserID = 123
+-----------------+------------------------+
| Competition     |     Competition 1      |
+-----------------+------------------------+
                      | Competition 2  |
                      | Competition 3  |  <- drop down list
                      | Competition 4  | 
                      +----------------+

在此管理表单

I want to have disabled competition drop down list if userId is not empty.

最佳答案

这可以使用纯 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>

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

关于forms - 如何在JSP中禁用下拉列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30750270/

相关文章:

java - 在JSP中,有没有一种方法可以将HttpServletRequest对象作为属性传递给另一个HttpServletRequest对象

jQuery 添加 http ://as prefix to text input if there is none

css - HTML5 表单选择字段直到悬停才显示

java.util.并发.ExecutionException : Failed to initialize component

java - 在javascript下使用表达式语言?

java - 显示标签 pdf 导出未下载

javascript - 在一页的标题中隐藏图像,仅限在线表格

php - 字段不是实体的有效字段 - DoctrineEncryptBundle Symfony

javascript - 如何使用jsp将mysql字符串存储在javascript变量中

Tomcat-从多个 Web 模块重定向到默认操作