审查生成的文章索引

来自 HTML 语义化元素
HTML Living Standard 高级 6分钟 找出 4处问题

在这段生成的文章索引渲染服务器数据前审查它。

安全地渲染可用键盘操作的文章链接列表,并提供页面标题与有意义的图片替代文本。

HTML
<div class="main">
  <div class="page-title">Latest articles</div>
  <div id="articles"></div>
</div>
<script>
  const posts = window.__POSTS__;
  const root = document.querySelector('#articles');
  root.innerHTML = posts.map((post) => `
    <div class="card" onclick="location.href='/posts/${post.slug}'">
      <img src="${post.image}">
      <div class="card-title">${post.title}</div>
      <div class="summary">${post.summary}</div>
    </div>
  `).join('');
  for (const card of root.children) {
    card.addEventListener('keydown', (event) => {
      if (event.key === 'Enter') card.click();
    });
  }
</script>

生成代码仅作示例,不代表任何特定模型

在试验场中打开
报告错误