在“我的帐户”登录页面上输入密码时显示密码

时间:2017-09-14 作者:Crashy

是否有办法在键入密码时不显示点数,而是显示密码的字母/数字?

我想在我的woocommerce“我的账户”页面中实现它:

enter image description here

3 个回复
最合适的回答,由SO网友:Drupalizeme 整理而成

我强烈反对显示password as the user typing it. 相反,您可以实现一种通过用户操作显示字段状态的方法,如user click 显示密码或打开hover.原因是用户决定显示密码。此外,提高安全性,因为用户在键入时可能并不孤单

例如:enter image description here代码来自herdiansc

//Place this plugin snippet into another file in your applicationb
(function ($) {
    $.toggleShowPassword = function (options) {
        var settings = $.extend({
            field: "#password",
            control: "#toggle_show_password",
        }, options);

        var control = $(settings.control);
        var field = $(settings.field)

        control.bind(\'click\', function () {
            if (control.is(\':checked\')) {
                field.attr(\'type\', \'text\');
            } else {
                field.attr(\'type\', \'password\');
            }
        })
    };
}(jQuery));

//Here how to call above plugin from everywhere in your application document body
$.toggleShowPassword({
    field: \'#test1\',
    control: \'#test2\'
});

jsfiddle

和用户Baraka Mahili

$(\'#show_password\').hover(function functionName() {
                        //Change the attribute to text
                        $(\'#password\').attr(\'type\', \'text\');
                        $(\'.glyphicon\').removeClass(\'glyphicon-eye-open\').addClass(\'glyphicon-eye-close\');
                    }, function () {
                        //Change the attribute back to password
                        $(\'#password\').attr(\'type\', \'password\');
                        $(\'.glyphicon\').removeClass(\'glyphicon-eye-close\').addClass(\'glyphicon-eye-open\');
                    }
                );
https://codepen.io/GBMahili/pen/pEvVZP

SO网友:Milan Petrovic

在不对代码进行太多更改的情况下,最好的方法是使用JavaScript(jQuery),它将向现有密码字段添加隐藏/显示功能。

优秀的免费jQuery插件:HideShowPassword. 它有许多方法可以自定义密码的显示方式。

SO网友:Harry

通过复制替代woocommerce/templates/myaccount/form-login.php. it收件人yourtheme/woocommerce/myaccount/form-login.php.

并更改密码字段属性type="password"type="text"

希望它能解决你的问题。

结束