<!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>
网友评论