gpt4 book ai didi

Javascript/jQuery 不适用于模糊

转载 作者:行者123 更新时间:2023-11-30 13:10:05 26 4
gpt4 key购买 nike

我在表单上有以下输入:

<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 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");
}
});

问题:

如果密码不匹配并且我更正了它们,blur 上的确认密码将按预期再次运行......这是正确的

现在,如果密码不匹配,我单击复选框以显示密码然后更正,确认密码将NOT再次运行模糊。

谁能看出是什么原因造成的?

最佳答案

单击复选框时,您将向页面插入动态内容,这就是模糊在此之后不起作用的原因。替换函数声明

$('.confirmpass').blur(function()

$(document).on('blur', '.confirmpass', function() 

关于Javascript/jQuery 不适用于模糊,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14200938/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com