123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- </head>
- <body>
- <script>
- function createPersonClosure(name='Иван', surname='Иванов'){
- let age = 30
- let fatherName = 'Иванович'
- let obj
- return obj = {
- getName: function (){return name},
- getSurname: function (){return surname},
- getFatherName: function (){return fatherName},
- getAge: function (){return age},
- getFullName: function (){return `${name} ${surname} ${fatherName} ${age}`},
- setName: function (newName){
- if(newName.slice(0,1)===newName.toUpperCase().slice(0,1)){
- name=newName
- return obj.getName()
- }
- else{return obj.getName()}
- },
- setSurname: function (newSurname){
- if(newSurname.slice(0,1)===newSurname.toUpperCase().slice(0,1)){
- surname=newSurname
- return obj.getSurname()
- }
- else{return obj.getSurname()}
- },
- setFatherName: function (newFatherName){
- if(newFatherName.slice(0,1)===newFatherName.toUpperCase().slice(0,1)){
- fatherName=newFatherName
- return obj.getFatherName()
- }
- else{return obj.getFatherName()}
- },
- setAge: function (newAge){
- if(newAge<100 && newAge>0){
- age=newAge
- return obj.getAge()
- }
- else{return obj.getAge()}
- },
- setFullName: function (newFullName){
- let [surnameCheck, nameCheck, fatherNameCheck] = newFullName.split(' ')
- 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)){
- [surname, name, fatherName] = newFullName.split(' ')
- return obj.getFullName()
- }
- else{return obj.getFullName()}
- }
- }
- }
- const b = createPersonClosure()
- //b.setAge(15)
- //b.setName("Анна")
- //b.setSurname("Петрова")
- //b.setFatherName("Николаевна")
- b.setFullName("Петрова Анна Николаевна")
- function personForm(parent, person){
- let inputName = document.createElement('input')
- let inputSurname = document.createElement('input')
- let inputFatherName = document.createElement('input')
- let inputAge = document.createElement('input')
- let inputFullName = document.createElement('input')
- inputName.value= person.getName()
- inputSurname.value= person.getSurname()
- inputFatherName.value= person.getFatherName()
- inputAge.value= person.getAge()
- inputFullName.value= person.getFullName()
- inputFullName.style.width="220px"
- parent.append(inputName)
- parent.append(inputSurname)
- parent.append(inputFatherName)
- parent.append(inputAge)
- parent.append(inputFullName)
- inputName.oninput = () => {
- person.setName(inputName.value)
- inputName.value= person.getName()
- }
- inputSurname.oninput = () => {
- inputSurname.value=person.setSurname(inputSurname.value)
- }
- inputFatherName.oninput = () => {
- inputFatherName.value=person.setFatherName(inputFatherName.value)
- }
- inputAge.oninput = () => {
- inputAge.value=person.setAge(inputAge.value)
- }
- inputFullName.oninput = () => {
- inputFullName.value=person.setFullName(inputFullName.value)
- }
- }
- let form = document.createElement('form')
- document.body.append(form)
- personForm(form, b)
- </script>
- </body>
- </html>
|