Changing the type of an input field using jQuery (text -> password)

前端 未结 5 2234
天涯浪人
天涯浪人 2020-12-15 10:17

I am trying to change type of input, specifically after click into input change type=\"text\" to change=\"password\".

I don\'t know why, but I can\'

5条回答
  •  情深已故
    2020-12-15 10:57

    I had exactly the same problem, I wanted to show a text in a password field until the user clicked over it. I did another approach, instead to try to change the type of the field I hide it and showed a new text field, then called the focus(). It works fine.

    $("#password_fake").focus(){
        $(this).hide();
        $("#password").show().focus();
    }
    

    where #password_fake is a text field and #password a password field with style="display:none".

提交回复
热议问题