复制的文件不起作用 - ID在不同页面HTML JavaScript PHP中不起作用


copied file not working - id not working across different pages html javascript php?

我有一个非常简单的任务,只是不起作用,我不知道为什么。 我有一个PHP文件(其中大部分是HTML),我只是将其复制到同一文件夹中的另一个文件中,期望具有相同的功能。 我有两个按钮,按下时应该会弹出一个窗口,但是在新页面中,每当按下按钮时,我都会在URL中得到表单的pageURL +#id,但没有任何反应。例如: "{/project/login.php#loginmode}"//是的,它在本地主机上

根据我的理解,id 在页面中必须是唯一的,但它们也应该在文件夹中的页面中是唯一的吗? 我尝试更改 id 名称,只是发现新的 id 名称显示在 URL 中。 我还尝试将原始文件复制到完全不同的目录,但仍然存在相同的问题。 然后我尝试在那里更改ID名称,但仍然没有。 我错过了什么?? 我已经重新启动了我的服务器并多次清除了我的缓存......

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf=8"/>
    <title>TITLE/title>
    <link rel="stylesheet" type="text/css" href="style.css" me2dia="screen" />
    <link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
    <link rel="icon" href="/favicon.ico" type="image/x-icon">       
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
    <link href='http://fonts.googleapis.com/css?family=Terminal+Dosis' rel='stylesheet' type='text/css' />
    <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
    <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
    <script type="text/javascript" src="js/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="js/jquery.leanModal.min.js"></script>
    <div id = "top">
        <center>
            <nav>
                <a class="navbtn" href="about.php" style="padding: 0px 10px 0px 10px">  ABOUT</a> |
                <a href="#loginmode" class="navbtn modaltrigger" style="padding: 0px 10px 0px 10px">  LOGIN  </a> |
                <a href="#contactmodal" class="navbtn modaltrigger" style="padding: 0px 10px 0px 10px"> CONTACT</a> 
            </nav>
        </center>
        </br></br></br>
    </div> 
    <!--script for checking logging and creating user--> 
    <script type = "text/javascript">  
        function checkLogin(){ 
            var u = document.getElementById("username").value;
            var p = document.getElementById("password").value;
            var xmlhttp;
            if (window.XMLHttpRequest) //using AJAX
              {// code for IE7+, Firefox, Chrome, Opera, Safari
              xmlhttp=new XMLHttpRequest();  
              }
            else
              {// code for IE6, IE5
              xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
              }
            //using AJAX:        
            xmlhttp.onreadystatechange = function(){
                if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
                    if(xmlhttp.responseText == u){
                        alert('You have entered a correct username and/or password.');
                        window.location = 'home.php'; //should change from home to newposting.php???
                    }
                    else{
                        alert('You have entered an incorrect username/password combination.  Please try again.');
                        //href='"javascript:history.go(-2)'"
                        //window.location = 'loginredo.php';                    
                    }
                }
            }
            xmlhttp.open("GET", "checkpw.php?u=" + u + "&p=" + p, true);
            xmlhttp.send(); 
        }
        function newUser(){
            location.href = 'signup.php';
        }
    </script>
</head>
<body>  
    <center>
    <!--Login-->
        <div id="loginmode" style="display:none;">
          <logh1>Sign In:</logh1>
          <form id="loginforme" name="loginforme" method="post" action="index.html">
            <label for="username"><h2>Username:</h2></label>
            <input type="text" name="username" id="username" class="txtfield" tabindex="1">
            <label for="password"><h2>Password:</h2></label>
            <input type="password" name="password" id="password" class="txtfield" tabindex="2">
            <div class="center">
                <input type="submit" name="loginbtn" id="loginbtn" class="flatbtn-blu hidemodal" value="Log In" onclick="checkLogin(); return false;" tabindex="3">
                <input type="submit" name="newusrbtn" id="create-user"" class="flatbtn-blu hidemodal" value="New User" onclick="newUser();" tabindex="4">
            </div>
          </form>
        </div>
    <!--Contact-->
        <div id="contactmodal" style="display:none;">
          <logh1>Contact GULSEN:</logh1>
          <form name="contactform" action="contact.php" method="post"> <!--cannot have id="contactform"-->
            <label for="cf_first_name"><h2>First Name</h2></label>
            <input type="text" name="cf_first_name" class="txtfield" tabindex="1">
            <label for="cf_last_name"><h2>Last Name</h2></label>
            <input type="text" name="cf_last_name" class="txtfield" tabindex="2">
            <label for="cf_email"><h2>Email Address</h2></label>
            <input type="text" name="cf_email" id="cf_email" class="txtfield" tabindex="3">
            <label for="password"><h2>Message</h2></label>
            <textarea name="cf_message" cols="100" rows="5" class="txtfield" tabindex="4" style="resize: none; outline: none"></textarea>      
            <label for="cf_reference"><h2>How did you hear about GULSEN?</h2></label>
            <input type="text" name="cf_reference" id="cf_reference" class="txtfield" tabindex="5">   
            <div class="center">  
              <input type="submit" class="flatbtn-blu" value="Send">
              <input type="reset" class="flatbtn-blu" value="Clear">
            </div>
          </form>
        </div>
    </center>  
    <script type="text/javascript">
        $(function(){
          $('#loginforme').submit(function(e){
            return false;
          });
        $('#contactform').submit(function(e){
            return false;
          });
          $('.modaltrigger').leanModal({ top: 110, overlay: 0.45, closeButton: ".hidemodal" });
        });
    </script>  
<div id="footer"></div>
</body>
</html>

尝试以下代码,

$(".modaltrigger").click(function(){
  var href= $(this).attr('href');
  $(href).show();
});

编辑但我怀疑JS文件没有正确加载。使用该工具查看您是否在浏览器控制台上收到任何错误Inspect Element