1. 程式人生 > >input框改變type屬性

input框改變type屬性

get input框 click 必須 cli cnblogs color inpu -s

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(‘顯示密碼‘)
     };
})

input框改變type屬性