Advertisement
Guest User

Untitled

a guest
Jan 19th, 2020
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. class Main {
  2.  
  3. // Конструктор
  4. constructor() {
  5. // input1, input2, button
  6. this.book = document.querySelector('.form-todo').children[0];
  7. this.author = document.querySelector('.form-todo').children[1];
  8. this.btn = document.querySelector('.form-todo').children[2];
  9. }
  10.  
  11. // Проверка
  12. check() {
  13. this.btn.addEventListener('click', (e) => {
  14. e.preventDefault();
  15.  
  16. if ( this.book.value == '' || this.author.value == '' ) {
  17. console.log('null');
  18. } else {
  19. this.add();
  20. }
  21. });
  22. }
  23.  
  24. // Добавить новую книгу
  25. add() {
  26. let array = [{
  27. book: 'Красная Таблетка',
  28. author: 'Андрей Курпатов'
  29. }];
  30.  
  31. array.push({
  32. book: this.book.value,
  33. author: this.author.value
  34. });
  35.  
  36. console.log(array);
  37. }
  38. }
  39.  
  40. let main = new Main();
  41. main.check();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement