<SCRIPT LANGUAGE="JavaScript">
function myFun(oSel){
if(oSel.options[oSel.selectedIndex].text == "自定义问题"){
document.getElementById('oDiv').innerHTML = "请输入自定义密码提示问题:<INPUT/>";
}else{
document.getElementById('oDiv').innerHTML = ""
}
}
</SCRIPT>
 <tr height="100pt"> 
<td>密码提示问题: </td> 
<td> 
<select name="pwdquestion" onchange='myFun(this)' > 
<option value="0" selected>请选择密码提示问题 </option> 
<option value="1">我最难忘的人是谁? </option> 
<option value="2">我的小学叫什么名字? </option> 
<option value="3">自定义问题 </option> 
</select> 
</td> 
</tr> 
<div id="oDiv"></div>

解决方案 »

  1.   

    我试过了,不行啊,还是上午那个程序
    <%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <base href="<%=basePath%>">
        
        <title>My JSP 'index.jsp' starting page</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
    <script type="text/javascript">
    function isEmail(str){
           var reg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/;
           if(reg.test(str)==true)
            return true;
    else{
    document.getElementById("str1").innerText="    邮箱地址格式不正确!";
    }
    }
      
    function pwdCheck(str){
    var reg=/^[a-zA-Z0-9]{6,16}$/;
    if(reg.test(str)==true)
            return true;
            else{
    document.getElementById("str2").innerText="    密码格式不正确!";
    }
    }

    function pwdConfirm(){
    if(document.forms[0].pwd1.value==document.forms[0].pwd2.value)
    return true;
    else
    document.getElementById("str3").innerText="    两次密码输入不一致,请重新输入!";
    }

    function myFun(oSel){
          if(oSel.options[oSel.selectedIndex].text == "自定义问题"){
             document.getElementById('oDiv').innerHTML = "请输入自定义密码提示问题:<INPUT/>";
         }else{
             document.getElementById('oDiv').innerHTML = ""
         }
    }

    function hide(sId){
    document.getElementById(sId).innerText="";
    }

    </script>
      </head>
      
      <body>
        <form name="register">
        <table>
         <tr height="100pt">
         <td>邮箱地址:</td>
         <td><input type="text" name="eml" onblur="isEmail(this.value)" onfocus="hide('str1')"/></td>
         <td><div id="str1">
         </div></td>
         </tr>
        
         <tr height="50pt">
         <td>密码:</td>
         <td><input type="password" name="pwd1" onblur="pwdCheck(this.value)" onfocus="hide('str2')"/></td>
         <td><div id="str2">
         </div></td>
         </tr>
        
          <tr height="50pt">
         <td><strong><em>密码由数字和英文字母组成,长度在6-16位之间</em></strong></td>
         </tr>
         <tr height="100pt">
         <td>确认密码:</td>
         <td><input type="password" name="pwd2" onblur="pwdConfirm()" onfocus="hide('str3')"/></td>
         <td><div id="str3">
         </div></td>
         </tr>
        
         <tr height="100pt">
         <td>密码安全级别:</td>
         <td width="50pt"><input type="radio" name="pwdlevel" value="low" checked/>低</td>
         <td width="150pt"><input type="radio" name="pwdlevel" value="middle"/>中</td>
         <td width="150pt"><input type="radio" name="pwdlevel" value="high"/>高</td>
         </tr>
        
         <td>密码提示问题: </td> 
    <td> 
    <select name="pwdquestion" onchange='myFun(this)' > 
    <option value="0" selected>请选择密码提示问题 </option> 
    <option value="1">我最难忘的人是谁? </option> 
    <option value="2">我的小学叫什么名字? </option> 
    <option value="3">自定义问题 </option> 
    </select> 
    </td> 
    </tr> 
    <div id="oDiv"></div>     <tr height="100pt">
         <td>密码提示问题答案:</td>
         <td><input type="text" name="answer" onblur="" onfocus=""/></td>
         <td><div id="str5">
         </div></td>
         </tr>
         </table>
        </form>
      </body>
    </html>
    按你的方法,选择自定义问题时,没有任何反应
      

  2.   

    在<td>密码提示问题: </td>
    上面掉了个<tr>,我加了后还是那样
      

  3.   

    又发现个问题,在<option value="3">自定义问题 </option>这儿有空格
    我去掉了,问题依旧
      

  4.   


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
    <html> 
      <head> 
        <base href=" <%=basePath%>"> 
        
        <title>My JSP 'index.jsp' starting page </title> 
    <meta http-equiv="pragma" content="no-cache"> 
    <meta http-equiv="cache-control" content="no-cache"> 
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> 
    <meta http-equiv="description" content="This is my page"> 
    <!-- 
    <link rel="stylesheet" type="text/css" href="styles.css"> 
    --> 
    <script type="text/javascript"> 
    function isEmail(str){ 
          var reg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/; 
          if(reg.test(str)==true) 
          return true; 
    else{ 
    document.getElementById("str1").innerText="    邮箱地址格式不正确!"; 


      
    function pwdCheck(str){ 
    var reg=/^[a-zA-Z0-9]{6,16}$/; 
    if(reg.test(str)==true) 
          return true; 
          else{ 
    document.getElementById("str2").innerText="    密码格式不正确!"; 

    } function pwdConfirm(){ 
    if(document.forms[0].pwd1.value==document.forms[0].pwd2.value) 
    return true; 
    else 
    document.getElementById("str3").innerText="    两次密码输入不一致,请重新输入!"; 

    function hide(sId){ 
    document.getElementById(sId).innerText=""; 
    } function myFun(oSel){ 
    alert(oSel.options[oSel.selectedIndex].text == "自定义问题")
      if(oSel.options[oSel.selectedIndex].text == "自定义问题"){ 
            document.getElementById('oDiv').innerHTML = "请输入自定义密码提示问题: <INPUT type='text' id='aa'/>"; 
        }else{ 
            document.getElementById('oDiv').innerHTML = "" 
        } 
    } </script> 
      </head> 
      
      <body> 
        <form name="register"> 
        <table> 
        <tr height="100pt"> 
        <td>邮箱地址: </td> 
        <td> <input type="text" name="eml" onblur="isEmail(this.value)" onfocus="hide('str1')"/> </td> 
        <td> <div id="str1"> 
        </div> </td> 
        </tr> 
        
        <tr height="50pt"> 
        <td>密码: </td> 
        <td> <input type="password" name="pwd1" onblur="pwdCheck(this.value)" onfocus="hide('str2')"/> </td> 
        <td> <div id="str2"> 
        </div> </td> 
        </tr> 
        
        <tr height="50pt"> 
        <td> <strong> <em>密码由数字和英文字母组成,长度在6-16位之间 </em> </strong> </td> 
        </tr> 
        <tr height="100pt"> 
        <td>确认密码: </td> 
        <td> <input type="password" name="pwd2" onblur="pwdConfirm()" onfocus="hide('str3')"/> </td> 
        <td> <div id="str3"> 
        </div> </td> 
        </tr> 
        
        <tr height="100pt"> 
        <td>密码安全级别: </td> 
        <td width="50pt"> <input type="radio" name="pwdlevel" value="low" checked/>低 </td> 
        <td width="150pt"> <input type="radio" name="pwdlevel" value="middle"/>中 </td> 
        <td width="150pt"> <input type="radio" name="pwdlevel" value="high"/>高 </td> 
        </tr> 
        
        <td>密码提示问题: </td> 
    <td> 
    <select name="pwdquestion" onchange='myFun(this)' > 
    <option value="0" selected>请选择密码提示问题 </option> 
    <option value="1">我最难忘的人是谁? </option> 
    <option value="2">我的小学叫什么名字? </option> 
    <option value="3">自定义问题 </option> 
    </select> 
    <div id="oDiv"> </div> 
    </td> 
    </tr> 
        <tr height="100pt"> 
        <td>密码提示问题答案: </td> 
        <td> <input type="text" name="answer" onblur="" onfocus=""/> </td> 
        <td> <div id="str5"> 
        </div> </td> 
        </tr> 
        </table> 
        </form> 
      </body> 
    </html> 
      

  5.   

    你把div放到<tr></tr>div<tr></tr>?????晕了
      

  6.   

    这 我按你的来的啊
    现在新问题出现,功能是可以实现了,但选择自定义问题时,alert出一个true,我再选别的,又alert出一个false,怎么去掉?
      

  7.   

    晕,你加了个alert,是调式用的吧,刚才没看见
      

  8.   


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
    <html> 
      <head> 
        <base href=" <%=basePath%>"> 
        
        <title>My JSP 'index.jsp' starting page </title> 
    <meta http-equiv="pragma" content="no-cache"> 
    <meta http-equiv="cache-control" content="no-cache"> 
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> 
    <meta http-equiv="description" content="This is my page"> 
    <!-- 
    <link rel="stylesheet" type="text/css" href="styles.css"> 
    --> 
    <script type="text/javascript"> 
    function isEmail(str){ 
          var reg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/; 
          if(reg.test(str)==true) 
          return true; 
    else{ 
    document.getElementById("str1").innerText="    邮箱地址格式不正确!"; 


      
    function pwdCheck(str){ 
    var reg=/^[a-zA-Z0-9]{6,16}$/; 
    if(reg.test(str)==true) 
          return true; 
          else{ 
    document.getElementById("str2").innerText="    密码格式不正确!"; 

    } function pwdConfirm(){ 
    if(document.forms[0].pwd1.value==document.forms[0].pwd2.value) 
    return true; 
    else 
    document.getElementById("str3").innerText="    两次密码输入不一致,请重新输入!"; 

    function hide(sId){ 
    document.getElementById(sId).innerText=""; 
    } function myFun(oSel){ 
    //alert(oSel.options[oSel.selectedIndex].text == "自定义问题")
      if(oSel.options[oSel.selectedIndex].text == "自定义问题"){ 
            document.getElementById('td1').innerHTML = "请输入自定义密码提示问题:"; 
    document.getElementById('td2').innerHTML="<INPUT type='text' id='aa'/>";
        }else{ 
            document.getElementById('td1').innerHTML = "";
    document.getElementById('td2').innerHTML = ""; 
        } 
    } </script> 
      </head> 
      
      <body> 
        <form name="register"> 
        <table> 
        <tr height="100pt"> 
        <td>邮箱地址: </td> 
        <td> <input type="text" name="eml" onblur="isEmail(this.value)" onfocus="hide('str1')"/> </td> 
        <td> <div id="str1"> 
        </div> </td> 
        </tr> 
        
        <tr height="50pt"> 
        <td>密码: </td> 
        <td> <input type="password" name="pwd1" onblur="pwdCheck(this.value)" onfocus="hide('str2')"/> </td> 
        <td> <div id="str2"> 
        </div> </td> 
        </tr> 
        
        <tr height="50pt"> 
        <td> <strong> <em>密码由数字和英文字母组成,长度在6-16位之间 </em> </strong> </td> 
        </tr> 
        <tr height="100pt"> 
        <td>确认密码: </td> 
        <td> <input type="password" name="pwd2" onblur="pwdConfirm()" onfocus="hide('str3')"/> </td> 
        <td> <div id="str3"> 
        </div> </td> 
        </tr> 
        
        <tr height="100pt"> 
        <td>密码安全级别: </td> 
        <td width="50pt"> <input type="radio" name="pwdlevel" value="low" checked/>低 </td> 
        <td width="150pt"> <input type="radio" name="pwdlevel" value="middle"/>中 </td> 
        <td width="150pt"> <input type="radio" name="pwdlevel" value="high"/>高 </td> 
        </tr> 
     <tr>
     
     </td>
        <td>密码提示问题: </td> 
    <td> 
    <select name="pwdquestion" onchange='myFun(this)' > 
    <option value="0" selected>请选择密码提示问题 </option> 
    <option value="1">我最难忘的人是谁? </option> 
    <option value="2">我的小学叫什么名字? </option> 
    <option value="3">自定义问题 </option> 
    </select> 
    </td> 
    </tr>  </td>
        <td id='td1'></td> 
    <td id = 'td2'> </td> 
    </tr>     <tr height="100pt"> 
        <td>密码提示问题答案: </td> 
        <td> <input type="text" name="answer" onblur="" onfocus=""/> </td> 
        <td> <div id="str5"> 
        </div> </td> 
        </tr> 
        </table> 
        </form> 
      </body> 
    </html>