JQuery .blur()不工作

时间:2015-02-21 12:20:03

标签: javascript jquery blur

基本上,我的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>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:1)

您的onblur无法正常工作,因为它未设置为密码元素。当用户点击您的密码输入时,他们会被一个带有makeitpassword#()功能的新密码取代。这会导致原始元素被删除,并且新元素没有附加模糊。丢失onfocus事件,你会没事的!

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

&#13;
&#13;
<input type="password" placeholder="password here">
&#13;
&#13;
&#13;