<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>去除标签</title>
<style>
.textareaS {
width: 100%;
height: 500px;
}
.btn {
background-color: #ccc;
width: 200px;
height: 100px;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
margin: 20px auto
}
</style>
</head>
<body>
<textarea class="textareaS"></textarea>
<div class="btn" onclick="matchReg()">一键生成并复制</div>
<script type="text/javascript">
function matchReg() {
let area = document.getElementsByClassName("textareaS")[0];
let str = area.value
let reg = /<[^>]+>/g
let newStr = str.replace(reg, '\n')
newStr = newStr.replace(/ /ig, '')
area.value = ''
// console.log(newStr);
let oInput;
if (!document.getElementsByClassName("oInput").length) {
oInput = document.createElement("textarea");
} else {
oInput = document.getElementsByClassName("oInput")[0];
oInput.style.display = "block";
}
oInput.value = newStr;
document.body.appendChild(oInput);
oInput.select();
document.execCommand("Copy");
oInput.className = "oInput";
oInput.style.display = "none";
console.log("复制成功");
}
matchReg(`<p>去除所有html标签,<img/><My-Tag class="abc" value="test">自定义标签也可以去除哦</My-Tag></p><p style="text-align: justify;
text-indent: 28pt"> aaa<p style="text-align: justify;
text-indent: 28pt">bbb `);
</script>
</body>
</html>