input框改变type属性

1、HTML部分

<input name="password" type="password" id="pass"  placeholder="密码"/>
<button>显示密码</button>

2.JS部分

$('button').on('click',function(){
   //必须用原生JS
   var pass =  document.getElementById('pass');
   if(pass.type == 'password'){
       pass.type = "text";
       $("button").text('隐藏密码')
   } else {
       pass.type = 'password';
       $("button").text('显示密码')
     };
})
原文地址:https://www.cnblogs.com/congxiu/p/7493059.html