Part1(Password).html 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Functional: OOP</title>
  6. </head>
  7. <body>
  8. <script>
  9. //---------Password ---- LoginForm ----
  10. function Password(parent,open=false){
  11. this.parent=parent;
  12. this.open=open;
  13. let key1=false;
  14. let key2=false;
  15. let login=document.createElement('input');
  16. login.type='text';
  17. login.placeholder='login';
  18. let input=document.createElement('input');
  19. input.placeholder='Password';
  20. let input2=document.createElement('input');
  21. input2.type='password';
  22. input2.placeholder='Password';
  23. let check=document.createElement('input');
  24. check.type='checkbox';
  25. check.checked=true;
  26. let p=document.createElement('p');
  27. let btn=document.createElement('input');
  28. btn.type='submit'
  29. btn.value='Autorized';
  30. parent.append(login,input,check);
  31. if(open==true){
  32. input.type='password';
  33. }
  34. if(open==false){
  35. input.type='text';
  36. }
  37. parent.append(p,btn);
  38. this.setValue=function(val){
  39. input.value=val;
  40. }
  41. login.value===''?key1=false:key1=true;
  42. key1===false?login.style.borderColor='red':login.style.borderColor='green';
  43. input.value===''?key1=false:key1=true;
  44. key2===false?input.style.borderColor='red':input.style.borderColor='green';
  45. parent.append(input2);
  46. input2.hidden=true;
  47. btn.disabled=true;
  48. login.onblur=function(){
  49. if(login.value==false){
  50. key2=false;
  51. login.style.borderColor='red';
  52. }else{
  53. key2=true;
  54. login.style.borderColor='green';
  55. if(key1===true){
  56. if(input.type==='text'){
  57. btn.disabled=false;
  58. }
  59. }
  60. }
  61. }
  62. /*setInterval(()=>console.log(key1+":"+key2),3000);*/
  63. input.onblur=function(){
  64. if(input.value==false){
  65. key1=false
  66. input.style.borderColor='red';
  67. }else{
  68. key1=true;
  69. input.style.borderColor='green';
  70. if(key2===true){
  71. if(input.type==='text'){
  72. btn.disabled=false;
  73. }
  74. if(input2.value===input.value){
  75. input2.borderColor='green';
  76. btn.disabled=false;
  77. }else{
  78. input2.borderColor='red';
  79. }
  80. /*setInterval(()=>console.log(input.type+":"+input2.value+":"+(input2.value===input.value)),2500);*/
  81. }
  82. }
  83. }
  84. btn.onclick=function(){
  85. console.log(login.value+":"+input.value);
  86. }
  87. this.getValue=function(){
  88. return input.value;
  89. }
  90. this.setOpen=function(val){
  91. val==true?input.type='password':input.type='text';
  92. check.checked=val;
  93. }
  94. check.onclick=function(){
  95. if(check.checked==true){
  96. input.type='password';
  97. let arr=(input.value).split('');
  98. for(let i=0;i<arr.length;i++){
  99. arr[i]='*';
  100. }
  101. p.innerText=arr.join('');
  102. input2.hidden=false;
  103. }else{
  104. input.type='text';
  105. p.innerText=input.value;
  106. input2.hidden=true;
  107. }
  108. }
  109. this.getOpen=function(){
  110. return input.type;
  111. }
  112. input.oninput=function(){
  113. p.innerText=input.value;
  114. }
  115. }
  116. let p=new Password(document.body,false);
  117. //p.setValue('qwerty');
  118. //console.log(p.getValue());
  119. p.setOpen(false);
  120. console.log(p.getOpen());
  121. </script>
  122. </body>
  123. </html>