index.html 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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>Document</title>
  8. </head>
  9. <body>
  10. <script>
  11. function createPersonClosure(name='Иван', surname='Иванов'){
  12. let age = 30
  13. let fatherName = 'Иванович'
  14. let obj
  15. return obj = {
  16. getName: function (){return name},
  17. getSurname: function (){return surname},
  18. getFatherName: function (){return fatherName},
  19. getAge: function (){return age},
  20. getFullName: function (){return `${name} ${surname} ${fatherName} ${age}`},
  21. setName: function (newName){
  22. if(newName.slice(0,1)===newName.toUpperCase().slice(0,1)){
  23. name=newName
  24. return obj.getName()
  25. }
  26. else{return obj.getName()}
  27. },
  28. setSurname: function (newSurname){
  29. if(newSurname.slice(0,1)===newSurname.toUpperCase().slice(0,1)){
  30. surname=newSurname
  31. return obj.getSurname()
  32. }
  33. else{return obj.getSurname()}
  34. },
  35. setFatherName: function (newFatherName){
  36. if(newFatherName.slice(0,1)===newFatherName.toUpperCase().slice(0,1)){
  37. fatherName=newFatherName
  38. return obj.getFatherName()
  39. }
  40. else{return obj.getFatherName()}
  41. },
  42. setAge: function (newAge){
  43. if(newAge<100 && newAge>0){
  44. age=newAge
  45. return obj.getAge()
  46. }
  47. else{return obj.getAge()}
  48. },
  49. setFullName: function (newFullName){
  50. let [surnameCheck, nameCheck, fatherNameCheck] = newFullName.split(' ')
  51. if(nameCheck.slice(0,1)===nameCheck.toUpperCase().slice(0,1) && fatherNameCheck.slice(0,1)===fatherNameCheck.toUpperCase().slice(0,1) && surnameCheck.slice(0,1)===surnameCheck.toUpperCase().slice(0,1)){
  52. [surname, name, fatherName] = newFullName.split(' ')
  53. return obj.getFullName()
  54. }
  55. else{return obj.getFullName()}
  56. }
  57. }
  58. }
  59. const b = createPersonClosure()
  60. //b.setAge(15)
  61. //b.setName("Анна")
  62. //b.setSurname("Петрова")
  63. //b.setFatherName("Николаевна")
  64. b.setFullName("Петрова Анна Николаевна")
  65. function personForm(parent, person){
  66. let inputName = document.createElement('input')
  67. let inputSurname = document.createElement('input')
  68. let inputFatherName = document.createElement('input')
  69. let inputAge = document.createElement('input')
  70. let inputFullName = document.createElement('input')
  71. inputName.value= person.getName()
  72. inputSurname.value= person.getSurname()
  73. inputFatherName.value= person.getFatherName()
  74. inputAge.value= person.getAge()
  75. inputFullName.value= person.getFullName()
  76. inputFullName.style.width="220px"
  77. parent.append(inputName)
  78. parent.append(inputSurname)
  79. parent.append(inputFatherName)
  80. parent.append(inputAge)
  81. parent.append(inputFullName)
  82. inputName.oninput = () => {
  83. person.setName(inputName.value)
  84. inputName.value= person.getName()
  85. }
  86. inputSurname.oninput = () => {
  87. inputSurname.value=person.setSurname(inputSurname.value)
  88. }
  89. inputFatherName.oninput = () => {
  90. inputFatherName.value=person.setFatherName(inputFatherName.value)
  91. }
  92. inputAge.oninput = () => {
  93. inputAge.value=person.setAge(inputAge.value)
  94. }
  95. inputFullName.oninput = () => {
  96. inputFullName.value=person.setFullName(inputFullName.value)
  97. }
  98. }
  99. let form = document.createElement('form')
  100. document.body.append(form)
  101. personForm(form, b)
  102. </script>
  103. </body>
  104. </html>