change type of input field with jQuery

后端 未结 29 2096
青春惊慌失措
青春惊慌失措 2020-11-22 05:13
$(document).ready(function() {
    // #login-box password field
    $(\'#password\').attr(\'type\', \'text\');
    $(\'#passwo         


        
29条回答
  •  伪装坚强ぢ
    2020-11-22 05:42

    It works much easier with that:

    document.querySelector('input[type=password]').setAttribute('type', 'text');
    

    and in order to turn it back to password field again,(assuming the password field is the 2nd input tag with text type):

    document.querySelectorAll('input[type=text]')[1].setAttribute('type', 'password')
    

提交回复
热议问题