gpt4 book ai didi

jquery - revalidateField 不起作用

转载 作者:行者123 更新时间:2023-12-01 04:04:49 25 4
gpt4 key购买 nike

我正在使用this plugin验证我的表单。

在我的表单上,我有一个密码输入和一个“显示密码”复选框。当用户单击“显示密码”时,输入从密码类型更改为文本。

$('#show_password').off();
$('#show_password').on('click', function() {
var change = '';
var $input = $('#cpassword');
if ($(this).is(':checked')) {
change = 'text';
} else {
change = 'password';
}
var rep = $('<input type="' + change + '" />')
.attr('id', $input.attr('id'))
.attr('name', $input.attr('name'))
.attr('class', $input.attr('class'))
.val($input.val())
.insertBefore($input);
$input.remove();
$input = rep;
$('#frm_user_details').formValidation('revalidateField', 'password');
});

所以基本上输入类型发生了变化(但保持相同的名称),我需要重新验证该字段,但它不起作用。

最佳答案

一个问题可能是因为您也克隆了密码字段的所有属性,甚至是 id。根据 w3 标准,您不应该有两个具有相同 ID 属性的元素。

所以你可以尝试下面的代码:

$('#show_password').off();
$('#show_password').on('click', function() {
var change = '';
var $input = $('#cpassword');
if ($(this).is(':checked')) {
change = 'text';
} else {
change = 'password';
}
var rep = $('<input type="' + change + '" />')
.attr('id', $input.attr('id')+'_text')
.attr('name', $input.attr('name'))
.attr('class', $input.attr('class'))
.val($input.val())
.insertBefore($input);
$input.remove();
$input = rep;
$('#frm_user_details').formValidation('revalidateField', 'password');
});

关于jquery - revalidateField 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30870902/

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