You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
zhishifufei_php/public/yhxy.html

71 lines
2.1 KiB

10 months ago
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>用户协议</title>
</head>
<style>
.bold {
font-weight: bold;
}
.italic {
font-style: italic;
}
.underline {
text-decoration: underline;
}
</style>
<body style="padding: 20px;">
<div id="content_id"></div>
</body>
<script>
fetch(location.origin + '/admin/index/ysxy?type=2')
.then(function (response) {
if (response.ok) {
return response.json();
} else {
throw new Error('请求接口失败');
}
})
.then(function (data) {
// 处理接口返回的数据
var content = document.getElementById("content_id");
content.innerHTML = parseRichText(data.data.content);
// document.getElementById("content_id").innerHTML =data.data.content;
})
.catch(function (error) {
console.log(error);
});
function parseRichText(text) {
var parser = new DOMParser();
var doc = parser.parseFromString(text, "text/html");
var parsedText = "";
var elements = doc.body.childNodes;
for (var i = 0; i < elements.length; i++) {
var element = elements[i];
if (element.nodeType === Node.TEXT_NODE) {
parsedText += element.textContent;
} else if (element.nodeType === Node.ELEMENT_NODE) {
var tagName = element.tagName.toLowerCase();
if (tagName === "strong") {
parsedText += "<span class='bold'>" + parseRichText(element.innerHTML) + "</span>";
} else if (tagName === "em") {
parsedText += "<span class='italic'>" + parseRichText(element.innerHTML) + "</span>";
} else if (tagName === "u") {
parsedText += "<span class='underline'>" + parseRichText(element.innerHTML) + "</span>";
} else {
parsedText += parseRichText(element.innerHTML);
}
}
}
return parsedText;
}
</script>
</html>