我找这个已经有一段时间了,但我似乎找不到任何答案。
基本上,我用JS编写了一个脚本来检查密码和确认密码的匹配性,但是这个脚本根本没有被调用,然后我用ESC键编写了另一个脚本来关闭弹出窗口,但即使这样也不起作用。我不知道哪里出了问题。任何帮助都将不胜感激。提前谢谢你。

<html>
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
      <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
      <meta name="Sell Punch" content="true">
      <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
      <title>Sell Punch Login</title>
      <link rel="stylesheet" type="text/css" href="http://localhost/Sell_Punch/assets/css/style.css">

      <script type="text/javascript">

        function ESCclose( evt ) {
          if ( evt.keyCode == 27 ) {
              console.log( 'escape pressed' );
          }
      }
      </script>

                 <script>

          var password = document.getElementById("password"), confirm_password = document.getElementById("repassword");

      function validatePassword(){
        if(password.value != confirm_password.value) {
          confirm_password.setCustomValidity("Passwords Don't Match");
        } else {
          confirm_password.setCustomValidity('');
        }
      }

      password.onchange = validatePassword;
      confirm_password.onkeyup = validatePassword;

      </script>



      <script>


      // Get the modal
      var modal = document.getElementById('id01');

      // Get the modal
      var modal = document.getElementById('id03');


      // When the user clicks anywhere outside of the modal, close it
      window.onclick = function(event) {
          if (event.target == modal) {
              modal.style.display = "none";
          }
      }
      </script>

      </head>
      <body onkeydown="ESCclose(event)">

      <button onclick="document.getElementById('id01').style.display='block'" class="m3">Login</button>

      <div id="id01" class="modal">
        <?php echo validation_errors(); ?>

      <?php echo form_open('verify1', 'class="modal-content animate"');?>

          <div class="imgcontainer">
            <span onclick="document.getElementById('id01').style.display='none'" class="close" title="Close Modal">&times;</span>

          </div>

          <div class="container">

        <center>
          <h1 > Login</h1>
          </center>
            <label><b>Email id</b></label>
            <input type="text" placeholder="Enter Email id" name="email" required>

            <label><b>Password</b></label>
            <input type="password" placeholder="Enter Password" name="password" required>

            <button class="but" type="submit" name="submit" value="Submit">Login</button>
          <br>
            <input type="checkbox" checked="checked">
          Remember me
          </div>

          <div class="container" style="background-color:#f1f1f1">
          <span align = "left"><a href="<?php echo site_url('Test/') ?>">Forgot Password?</a></span>
          <span align = "right"> New User? - <a href="#" onclick="document.getElementById('id03').style.display='block';document.getElementById('id01').style.display='none';"> Register Now</a>
            </span>
          </div>
        </form>
      </div>



      <div id="id03" class="modal">
        <?php echo validation_errors(); ?>


      <form role="form" name="signup" method="post" class="modal-content animate" action="<?php echo site_url('verify2');?>" >

          <div class="imgcontainer">
            <span onclick="document.getElementById('id03').style.display='none'" class="close" title="Close Modal">&times;</span>

          </div>

          <div class="container">
          <center>
            <h1 > Sign Up</h1>
            </center>
            <label><b>Name</b>
            <input type="text" placeholder="Enter your full name" name="name" id ="name" maxlength="40" required>
            </label>

            <label><b>Email id</b></label>
            <input type="text" placeholder="Email id" pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$" name="email" id ="email" maxlength="70" required>
          <label><b>Mobile No</b></label>
           <input type="text" placeholder="Mobile No." pattern="[7-9]{1}[0-9]{9}" maxlength="10" name="mob" required>

            <label><b>Password</b></label>
            <input type="password" placeholder="Enter minimum 6 digit Password" pattern=".{6,}" name="password" id="password" required>
             <label><b>Confirm Password</b>
            <input type="password" placeholder="Confirm your Password" pattern=".{6,}" name="repassword" id="repassword" required>
            </label>

             <button class="but" type="submit" name="submit" id = "submit" value="submit"> Submit</button>

          <div class="container" style="background-color:#f1f1f1">
          Already registerd - <a href="#" onclick="document.getElementById('id01').style.display='block';document.getElementById('id03').style.display='none';"> Login</a>
          </div>
          <?php echo form_close();?>


          </div>
        </form>
      </div>




      </body>

    </html>

最佳答案

试着在表格后面最后加上剧本

关于javascript - 用codeIgniter的view部分编写的Javascript无法正常工作,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44044835/

10-16 07:25