在codeIgniter的视图部分编写的Javascript不起作用

在codeIgniter的视图部分编写的Javascript不起作用,javascript,php,html,codeigniter,Javascript,Php,Html,Codeigniter,我一直在寻找这个问题已经有一段时间了,但我似乎没有找到任何答案。 基本上,我已经用JS编写了一个脚本,用于检查密码和确认密码的匹配情况,但根本没有调用该脚本,然后我编写了另一个脚本,使用ESC键关闭弹出窗口,但即使这样也不起作用。我不知道哪里出了问题。任何帮助都将不胜感激。先谢谢你 <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&

我一直在寻找这个问题已经有一段时间了,但我似乎没有找到任何答案。 基本上,我已经用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>

销售打孔登录
功能关闭(evt){
如果(evt.keyCode==27){
console.log('escape pressed');
}
}
var password=document.getElementById(“密码”),confirm_password=document.getElementById(“重新密码”);
函数validatePassword(){
if(password.value!=确认密码.value){
确认_password.setCustomValidity(“密码不匹配”);
}否则{
确认密码。设置自定义有效性(“”);
}
}

password.onchange=validatePassword; 确认\u password.onkeyup=validatePassword; //获取模态 var modal=document.getElementById('id01'); //获取模态 var modal=document.getElementById('id03'); //当用户单击模式之外的任何位置时,将其关闭 window.onclick=函数(事件){ 如果(event.target==模态){ modal.style.display=“无”; } } 登录
最后尝试包含脚本,在表单之后

对不起,我是StackOverflow新手。我已经上传了我的代码,请仔细检查。@JYoThI我认为ID是唯一的,它是一个密码,另一个密码。控制台中有什么错误?只需提醒脚本中的某些内容并检查一下。警报(val);var password和repassword为null,因为它是在dom加载@yadhubabu之前加载值实际上,我只是这样做了,它不起作用,所以我在某个地方读到,脚本应该在头部主体之前,这就是为什么我这样做,但它仍然不起作用。password.onchange=validatePassword;password.onchange=validatePassword();