在Web开发中,DIV(Division)是一个块级元素,用于布局和样式化网页内容。刷新DIV内容通常指的是动态更新DIV内部的HTML内容,以实现页面的实时更新。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Refresh DIV Content</title>
</head>
<body>
<div id="content">
Initial content
</div>
<button onclick="refreshContent()">Refresh</button>
<script>
function refreshContent() {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
document.getElementById("content").innerHTML = xhr.responseText;
}
};
xhr.open("GET", "https://api.example.com/data", true);
xhr.send();
}
</script>
</body>
</html>
通过以上方法,你可以有效地刷新DIV内容,提升用户体验和页面性能。
领取专属 10元无门槛券
手把手带您无忧上云