JQuery .blur() Not Working
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无法工作,因为它没有设置为password元素。当用户点击您的密码输入时,它们会被具有makeitpassword#()
功能的新密码所取代。这会导致原始元素被删除,而新元素上没有模糊。失去聚焦事件,你就没事了!
如果要在输入中显示消息,请使用placeholder
:
<input type="password" placeholder="password here">
相关文章:
- $rootScope not working
- jQuery document.ready not working
- Javascript getElementsByTagName not working?
- JQuery.val( ) not working
- Tomcat websocket is not working
- Javascript JSON.parse not working
- NodeJS Multer is not working
- Regex not working
- Ember run.debounce not working
- AngularJs 1 not working
- document.getElementById.style.backgroundImage not working
- Rxjs5, distinct() is not working
- createOscillator noteOn not working
- Javascript - .getHours() not working
- Javascript setTimeout not working | onkeydown
- MongoDB $pull not working
- Express router.use not working
- JSONP not working
- window.opener not working in chrome & IE
- Backbone + RequireJS: Collection.each() is not working