Сообщество IT-специалистов
Ответы на любые вопросы об IT
Профессиональное развитие в IT
Удаленная работа для IT-специалистов
<!DOCTYPE html> <html lang="ry"> <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>Список статей</title> <link rel="stylesheet" href="style.css"> <script src="main.js" defer></script> </head> <body> </body> </html>
(()=>{ const title = document.createElement('h1') title.textContent = "Список статей" document.body.append(title) async function getArticles(){ fetch('https://gorest.co.in/public/v1/posts') .then(r => { let arr = r.json() return arr }) .then(r => { document.body.insertAdjacentHTML('beforeend', ` <ul>${r.data.map(n => ` <li> <a href="article.html">${n.title}</a> </li>`).join('')} </ul> `); }); } getArticles() let notesOnPage =3; const pages = document.createElement('li') document.body.append(pages) for(let page of pages){ page.addEventListener('click', function(){ let pageNum = +this.innerHTML; let start =(pageNum - 1) * notesOnPage let end = start + notesOnPage let notes = arr.slice(start, end) console.log(notes) }) } })()
<!DOCTYPE html> <html lang="ru"> <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>Статья</title> <script src="index.js" defer></script> </head> <body> <h1>Article</h1> </body> </html>
(()=>{ async function getArticle(){ fetch('https://gorest.co.in/public/v1/posts') .then(r => r.json()) .then(r => { document.body.insertAdjacentHTML('beforeend', ` <h1>${r.data.map(n => `${n.title}</h1>`).join('')} <p>${r.data.map(n => `${n.body}</p>)`).join('')}`); }); } getArticle() })
main.js
второй HTML
index.js