我想让它成为您的名字,如果您的名字是Bob,那么如果您不是Bob,那么您正在注册。对不起,您没有访问权限,但我不知道我在做什么错,有人可以帮助我谢谢。

          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
          <html xmlns="http://www.w3.org/1999/xhtml">
         <head>
        <title></title>
        <meta http-equiv="content-type" content="text/html;charset=iso-8859-1" />
           </head>
           <script type="text/javascript">
           function verify() {
            var name="Please enter your name: ";
          if (firstName=="Bob") {
          alert("Now registered");
          }
        else {
         window.alert("Sorry you aren't allowed acess.")
        return false;
           }
       </script>
       <form name="myForm" action="#" method="post" enctype="text/plain">
        <input type="text" name="BOB">First Name<br>
        <input type="button" value="Submit" onclick="verify();">
        </form>
       </body>
        </html>

最佳答案

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
              "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
              <html xmlns="http://www.w3.org/1999/xhtml">
             <head>
            <title></title>
            <meta http-equiv="content-type" content="text/html;charset=iso-8859-1" />
               </head>
               <script type="text/javascript">
               function verify() {
                var name="Please enter your name: ";
var firstName = document.getElementById('firstName').value;
              if (firstName=="Bob") {
              alert("Now registered");
    return true;
              }
            else {
             window.alert("Sorry you aren't allowed acess.")
            return false;
               } }
           </script>
           <form name="myForm" action="#" method="post" onsubmit="return verify();" enctype="text/plain">
            <input id="firstName" type="text" name="BOB"/>First Name<br>
            <input type="button" value="Submit"/>
            </form>
           </body>
            </html>

您必须在表单标签上使用onsubmit,并且必须返回true或false

关于javascript - 有人可以告诉我我在做什么错,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5222394/

10-10 05:08