Javascript 文件名更改后无法正常工作

Javascript not working after filename change

我为我的网站创建了一个简单的注册(注册)表格。

表单包括一些有效性检查(例如:确保电子邮件格式正确;确保用户名不存在于数据库中;等等)

所有这些都需要 JS,我提供了适当的 JS 函数,并在我的文件中包含了一个 JS 脚本:

 **<script src="jquery-1.11.2.js" type="text/javascript"></script>**

一切都运行良好............直到我将注册文件的名称从“index.html”更改为“signup.php"

现在,一切都搞砸了。该表格仍然有效。但是,JS 函数和有效性检查都死了!没有任何效果。

Whosebug 上没有类似的问题;但是,我在 google 上找到了一个问题。发布者建议使用 "Javascript Initialization" 来解决问题,但他没有提供具体示例。

这是我的 JS 代码:

 <script src="jquery-1.11.2.js" type="text/javascript"></script>

 <script type="text/javascript">
 $(document).ready(function() {  

//the min chars for username  
var min_chars = 4;  

//result texts  
var characters_error = 'You must enter a minimum of 4 characters!';  
var checking_html = 'Checking Username Availability....';  

//when button is clicked  
$('#login').keyup(function(){    
    //run the character number check  
    if($('#login').val().length < min_chars){  
        //if it's bellow the minimum show characters_error text '  
        $('#username_availability_result').html(characters_error);  
    }else{  
        //else show the cheking_text and run the function to check  
        $('#username_availability_result').html(checking_html);  
        check_availability();  
    }  
 });  

 $('#email').keyup(function(){    
    //run the character number check  
    if($('#email').val().length > 0 ) {  
        //if it's bellow the minimum show characters_error text '  
        $('#email_availability_result').html(checking_email);
         }
    else{  
        //else show the cheking_text and run the function to check  
        $('#email_availability_result').html(checking_email);  
        check_email();  
    }  
  });

 });  

//function to check username AND email availability  

function check_availability(){  

//get the username  
var login = $('#login').val(); 
var button_check=true;

//use ajax to run the check  
$.post("check.php", { login: login },  
    function(result){  
        //if the result is 1  
        if(result == 1){  
            //show that the username is available  
            button_check=false; 
            document.getElementById("submit").disabled = false;
            $('#username_availability_result').html(login + ' is    
     available.');  
        }else{  
            //show that the username is NOT available 
            button_check=true; 
            document.getElementById("submit").disabled = true;
            $('#username_availability_result').html('Sorry, but [' + login +  
     '] is not available. Please choose another username.');
             }  
    });  
   }  

此脚本检查 "username availability" 以及用户名 "a minimum of 4 characters" 和 "email availability",等等

(我没有输入完整的代码,因为我认为没有必要)。这些只是我的部分代码的示例。

这是表格(用户名的输入条目)

选择一个用户名:

更新

我解决了为什么 JS 函数不起作用的问题:我必须指定 JS 源文件的完整路径,从 https://.. ....ETC。

但是,有些事情仍然不清楚:表单显示消息 "Checking Username Availability".........或 "Checking Email Validity"。但是,如果用户名是 available/unavailable,或者电子邮件是 valid/invalid......它不会显示这些消息!

"Checking Username Availability" 消息仍然停留在显示屏上 :((

已找到答案。

我犯了一个简单而愚蠢的错误(哈哈)

将文件名更改为"sign-up.php"后,我忘记删除PHP扩展名。所以,很自然地,我的服务器不知道去哪里找它