随机名言警句

2023-04-05  本文已影响0人  xueyueshuai


<!DOCTYPE html>
<html>
<head>
<title>显示API回复内容的示例</title>
</head>
<body>
<h1>随机名言警句</h1>
<div id="quotes"></div>

<script>
  // 使用Fetch API调用API
  fetch('https://api.quotable.io/random')
    .then(response => response.json())
    .then(data => {
      // 将API回复存储在变量中
      const quote = data.content;
      
      // 将API回复内容插入到页面元素中
      const quotesElement = document.getElementById('quotes');
      quotesElement.innerHTML = quote;
    })
    .catch(error => console.error(error));
</script>

</body>
</html>

上一篇 下一篇

猜你喜欢

热点阅读