基本上,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>
发布于 2015-02-21 12:28:21
您的onblur不工作,因为它没有设置为密码元素。当用户单击密码输入时,它们将被带有makeitpassword#()函数的新输入所取代。这会导致原始元素被移除,并且新元素没有一个模糊附加到它。失去焦点事件,你就会没事的!
如果要在输入中显示消息,请使用placeholder
<input type="password" placeholder="password here">
https://stackoverflow.com/questions/28645725
复制相似问题