JQuery.blur() 不工作

JQuery .blur() Not Working

基本上,我在 Jquery 中的 Blur() 函数没有被激活。我的代码在下面,我正在使用一个特殊的 .notify jquery 添加。我认为函数的实际主体没有任何问题,但它更多地与 .blur() 函数本身有关。

$(document).ready(function(e) {
  
  $("#verifypassword").blur(function(e) {
  var password1=document.getElementById("password").value;
  var password2=document.getElementById("verifypassword").value;
    if(password1!=password2){
    $("#verifypassword").notify("Passwords do not match.");
    }
    else{
       $("#verifypassword").notify("Passwords match!");
    }
   });
});

  
  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>The KGV Connection</title>
<link rel="stylesheet" type="text/css" href="stylesheet.css" />
<script src="jquery-2.1.1.min.js"></script>
<script src="animation.js"></script>
<script src="notify.js"></script>
</head>

<body>

<script type="text/javascript">
function makeitpassword(){
 var passform= document.getElementById("passcontainer");
 passform.innerHTML="<input type=\"password\" class=\"signuser\"id=\"password\" value=\"\"/>";
 document.getElementById("password").focus();
 }
function makeitpassword2(){

  var passform= document.getElementById("passcontainer2");
 passform.innerHTML="<input type=\"password\" class=\"signuser\" id=\"verifypassword\" value=\"\" onfocus=\"makeitpassword2()\"/>";
 document.getElementById("verifypassword").focus();

 }

</script>
  <div class="signup">
<h1 class="signheader">Sign Up</h1>
<br />
<form id="signup" action="signup.php" method="post">
<input type="text" class="signuser" name="username" value="Username"/>
<div id="passcontainer">
<input type="text" class="signuser" value="Password" id="password" onfocus="makeitpassword()" name="Password"/>
</div>

<div id="passcontainer2">
<input type="text" class="signuser" id="verifypassword" onfocus="makeitpassword2()" value="Repeat Password" name="VerifyPassword"/>
</div>

<input type="email" class="signuser" value="Email" name="Email"/>

<br />

<br />
<input type="submit" value="Sign Up" class="logsubmit"/>
</form>
</div>

  </body>

你的 onblur 没有工作,因为它没有设置密码元素。当用户点击您的密码输入时,他们将被替换为具有您的 makeitpassword#() 功能的新密码。这会导致删除原始元素,并且新元素不会附加模糊。失去焦点事件,你会没事的!

如果要在输入中显示消息,请使用 placeholder:

<input type="password" placeholder="password here">