Make Input Type=“Password” Use Number Pad on Mobile Devices

前端 未结 7 1449
轮回少年
轮回少年 2020-11-29 23:39

On my site designed for mobile devices I have an input field that is used for PIN numbers. I want the text to be hidden as it is entered and I want the number pad to pop up

7条回答
  •  孤城傲影
    2020-11-30 00:15

    Why don't you set the input with type="number" and use jQuery to change the type after a keydown in the input.

    $("input").keydown(function () {
        $(this).prop('type', 'password');
    });
    

    Then if you have made a mistake. You could clear the input and set once again the type="number".

    $("input").click(function () {
        $(this).val('');
        $(this).prop('type', 'number');
    });
    

    This is my first answer and I hope I've helped.

提交回复
热议问题