我在表单上有以下输入:
<input class="password" type="password" title="Your Password" name="password" size="30" autocomplete="off" value="" >
<input class="confirmpass" type="password" title="Confirm Password" name="pass_confirm" size="30" autocomplete="off" value="" >
<div class="jresults" align="left" style="display:none;" id="confirmdata"></div>
<input class="showpassword" type="checkbox" title="Show Passwords">
这是show passwords功能:
//Show password function
$(".showpassword").click(function()
{
var change = $(this).is(":checked") ? "text" : "password";
var password = $("input.password");
var showpass = $("<input type='" + change + "' />")
.attr("id", password.attr("id"))
.attr("title", password.attr("title"))
.attr("name", password.attr("name"))
.attr("size", password.attr("size"))
.attr('class', password.attr('class'))
.val(password.val())
.insertBefore(password);
password.remove();
password = showpass;
var confirmpass = $("input.confirmpass");
var showconfirm = $("<input type='" + change + "' />")
.attr("id", confirmpass.attr("id"))
.attr("title", confirmpass.attr("title"))
.attr("name", confirmpass.attr("name"))
.attr("size", confirmpass.attr("size"))
.attr('class',confirmpass.attr('class'))
.val(confirmpass.val())
.insertBefore(confirmpass);
confirmpass.remove();
confirmpass = showconfirm;
});
这是确认密码匹配功能:
//match passwords entered
$('.confirmpass').blur(function()
{
var Pass = $('.password').val();
var cPass = $('.confirmpass').val();
$('#confirmdata').css("display","none");
if(cPass.length>5)
{
if (Pass != cPass)
{
$('#confirmdata').css("display","block");
$('#confirmdata').css("color","#ff0000");
$('#confirmdata').html("No Match");
$("input.confirmpass").focus();
return;
}
$('#confirmdata').css("display","block");
$('#confirmdata').css("color","#00BB00");
$('#confirmdata').html("Matched");
}
});
问题:
如果密码不匹配并且我更正了,模糊的确认密码将按预期再次运行..... 这是正确的
现在,如果密码不匹配,我点击复选框显示密码然后更正,确认密码将不再次运行模糊。
任何人都可以看到可能导致这种情况的原因吗?
答案 0 :(得分:3)
单击复选框时,您将向页面插入动态内容,这就是为什么模糊不起作用的原因。替换函数声明
$('.confirmpass').blur(function()
与
$(document).on('blur', '.confirmpass', function()