<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.box,
.box1,
.box2 {
transition: 2s linear all;
}
.box {
opacity: 0;
}
.box1 {
opacity: 1;
color: red;
}
.box2 {
opacity: 1;
color: green;
}
</style>
</head>
<body>
<input type="text">
<div class="box"></div>
<script>
const input = document.querySelector('input')
const box = document.querySelector(".box")
let aee1 = ''
input.addEventListener('focus',function() {
box.classList.remove('box1')
box.classList.remove('box2')
})
input.addEventListener('blur',function() {
if (/精选/g.test(input.value)) {
alert('含有敏感词')
aee1 = input.value.replace(/精选/g,'&&')
// box.innerHTML = `敏感词:精选`
// box.classList.add('box1')
} else {
box.innerHTML = `验证通过`
box.classList.add('box2')
}
})
</script>
</body>
</html>
JavaScript敏感词替换【基础】
最新推荐文章于 2024-05-29 17:47:12 发布
本文主要介绍如何使用JavaScript进行敏感词的检测与替换,适用于网页内容审查和用户输入过滤,通过创建敏感词库和匹配算法,确保内容的安全性。
3062

被折叠的 条评论
为什么被折叠?



