下面的Jquery工作正常,但我如何缩短这个Jquery?我必须显示和隐藏密码和确认密码的密码?https://jsfiddle.net/c5cvLo54/1/
$(".password-showhide .show-password").click(function() {
$("#password").attr("type", "text");
$(".password-showhide .show-password").hide();
$(".password-showhide .hide-password").show();
});
$(".password-showhide .hide-password").click(function() {
$("#password").attr("type", "password");
$(".password-showhide .hide-password").hide();
$(".password-showhide .show-password").show();
});
$(".confirm-password-showhide .show-password").click(function() {
$("#confirmPassword").attr("type", "text");
$(".confirm-password-showhide .show-password").hide();
$(".confirm-password-showhide .hide-password").show();
});
$(".confirm-password-showhide .hide-password").click(function() {
$("#confirmPassword").attr("type", "password");
$(".confirm-password-showhide .hide-password").hide();
$(".confirm-password-showhide .show-password").show();
});
9条答案
按热度按时间rmbxnbpk1#
以下是其中一种方法,可以缩短代码:
ecbunoof2#
您只能使用一个按钮来控制。
联属萨摩亚
超文本标记语言:
中央支助组:
watbbzwu3#
我创建了这个基本上是通过参考谷歌的显示密码切换他们的登录形式。
这基本上是检查复选框是否被选中。
如果选中,则将密码的输入类型更改为文本,反之亦然。
0sgqnhkj4#
这是我认为你能得到的最短的了
我还删除了每个密码的“隐藏”范围。
x一个一个一个一个x一个一个二个x
lymnna715#
显示/隐藏密码功能
7hiiyaii6#
sqyvllje7#
r7knjye28#
下面是一个示例,说明如何在密码文本框中添加眼睛图标,并使用CSS和JavaScript切换密码的可见性:
axkjgtzd9#