如下例所示,当用户在用户名输入框中输入'222'后令牌输入框将隐藏。修改后会再次出现。

<html>
    <head>
        <title>测试动态表单</title>
        <meta charset="utf-8">
        
    </head>
    <body>
        <script type="text/javascript">
          
          function optChange(){            
            var username1=document.loginform.username.value;
            document.getElementById( "token").style.display= "block"; 
            if (username1==='222'){
            document.getElementById( "token").style.display= "none"; 
            }            
          }
        </script>
        <form name="loginform">
            <input id="username" onchange="optChange()">请输入用户名<br>
            <input id="password">请输入密码<br>
            <div id="token">
                <input>请输入令牌
            </div>
        </form>
    </body>
</html>