Common password input box when the input character will be replaced by the ' * ', and there will be a small eye to see the original character, although the input tag has this function, but this is only when they are looking at the regular expression when suddenly thought, as a practice, the manual implementation of their own:
1 <Body>2 <inputtype= "text"ID= "PSW"><ButtonID= "Show">Show</Button>3 <Script>4 varPSW=document.getElementById ('PSW'),5 Show=document.getElementById ('Show'),6 Array= [],7 pattern= /\w/G;8 psw.onkeypress= function(e) {9 Array.push (String.fromCharCode (E.charcode));//put the characters of each key into an arrayTen This. Value= This. Value.replace (Pattern,'*');//Replace the original character One } A Psw.onkeydown= function(e) { - if(E.keycode== 8){ //when you press DELETE to build, the array also deletes items from the tail. - Array.pop (); the Console.log (Array) - } - } - Show.onmousedown= function(){ //simulates small eyes and displays the original characters when pressed + Console.log (2) - Psw.value=Array.join ("'); + } A Show.onmouseup= function() {//Show ' * ' when released at Console.log (3) - Psw.value=Psw.value.replace (Pattern,'*'); - } - Psw.onblur= function() { - This. Value= This. Value.replace (Pattern,'*'); - } in </Script> - </Body>
JavaScript implements a simple password entry function