ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
## 输入内容中有敏感词过滤成* ``` <style> #res{ width: 200px; height: 200px; border:1px solid #ccc; } </style> <h2>敏感词过滤</h2> <p> <textarea name="" id="area" cols="30" rows="10"></textarea> </p> <p> <input type="submit" value="发布" id="input"> </p> <p id="res"></p> <script> // 逻辑:用户输入的值,如果和正则匹配到了,则进行替换 // 敏感词 使用* 替换 let area = document.getElementById('area'); let input = document.getElementById('input'); let res = document.getElementById('res'); let reg = /打酱油|划水/g; input.onclick = function(){ let newVue = area.value.replace(reg,'*'); res.innerText = newVue; } </script> ``` 效果图: ![](https://img.kancloud.cn/79/cd/79cd83fa29a45a0dfbc2ac4a1f79caf7_332x528.png)