Javascript 如果单击“编辑”选项,则“切换密码”不起作用
第一次Javascript 如果单击“编辑”选项,则“切换密码”不起作用,javascript,jquery,ajax,codeigniter,Javascript,Jquery,Ajax,Codeigniter,第一次切换密码工作正常,但当我单击“编辑模型”时,模型将打开。关闭模型后,表中的切换密码无效。我不知道为什么它不起作用。谁能帮帮我吗 $(“.toggle password”)。单击(函数(){ $(this.toggleClass(“fa-eye-fa-eye-slash”); 变量输入=$($(this.attr(“切换”)); if(input.attr(“type”)=“password”){ 警报(“测试”); input.attr(“类型”、“文本”); }否则{ 输入属性(“类型”
切换密码
工作正常,但当我单击“编辑模型”时,模型将打开。关闭模型后,表中的切换密码
无效。我不知道为什么它不起作用。谁能帮帮我吗
$(“.toggle password”)。单击(函数(){
$(this.toggleClass(“fa-eye-fa-eye-slash”);
变量输入=$($(this.attr(“切换”));
if(input.attr(“type”)=“password”){
警报(“测试”);
input.attr(“类型”、“文本”);
}否则{
输入属性(“类型”、“密码”);
}
});
如下所示更新您的代码。这将触发异步元素的事件
$(document).on("click", ".toggle-password", function() {
$(this).toggleClass("fa-eye fa-eye-slash");
var input = $($(this).attr("toggle"));
if (input.attr("type") == "password") {alert('test');
input.attr("type", "text");
}
else {
input.attr("type", "password");
}
});
您是否使用Ajax加载此div?第二次尝试时在控制台中是否看到任何错误?请注意,
toggle
不是span
元素的有效属性。您应该使用数据
属性,但最好不要使用动态创建的id
,而只使用DOM遍历。