index.html 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>A-Level</title>
  8. </head>
  9. <body>
  10. <script>
  11. function Password(parent, open){
  12. const pass = document.createElement('input')
  13. const btn = document.createElement('button')
  14. const lgn = document.createElement('input')
  15. const sbmt = document.createElement('button')
  16. sbmt.innerText = 'Submit'
  17. lgn.placeholder = "login"
  18. pass.placeholder = "password"
  19. btn.innerText = 'Show'
  20. parent.prepend(sbmt)
  21. parent.prepend(btn)
  22. parent.prepend(pass)
  23. parent.prepend(lgn)
  24. btn.addEventListener('click', () => this.setOpen(!this.open))
  25. btn.addEventListener('click', () => {
  26. btn.innerText = (btn.innerText === 'Show') ? btn.innerText = 'Hide' : btn.innerText = 'Show';
  27. })
  28. sbmt.setAttribute('disabled', true)
  29. oninput = () =>{
  30. if(pass.value.length < 1 || lgn.value.length < 1 ){
  31. sbmt.setAttribute('disabled', true)
  32. }
  33. else{
  34. sbmt.removeAttribute('disabled')
  35. }
  36. }
  37. this.open = open
  38. this .setOpen = (value) => {
  39. this.open = value
  40. render()
  41. }
  42. this.getOpen = () => {
  43. return this.open
  44. }
  45. const render = () => {
  46. pass.setAttribute('type', `${this.open ? 'text' : 'password'}`);
  47. lgn.setAttribute('type', `${this.open ? 'text' : 'password'}` );
  48. }
  49. return render()
  50. }
  51. let p = new Password(document.body, false)
  52. </script>
  53. </body>
  54. </html>