(6)敏感词过滤

代码:

<!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>
  </head>
  <body>
    <textarea name="" id="" cols="30" rows="10" id="area"> </textarea>
    <textarea name="" id="" cols="30" rows="10" id="text2"> </textarea>
    <button id="btn">发布</button>
    <script>
   let text=document.querySelectorAll('textarea')
//    console.log(text);
    //   console.log(text1);
      let btn = document.getElementById("btn");
      let reg = /金三胖|妈的/g;
      btn.addEventListener("click", function () {
        let newValue=text[0].value.replace(reg,'*')
        console.log(newValue);
      });
    </script>
  </body>
</html>

代码思路分析:

通过获取第一个表单的值,然后通过正则进行替换。

猜你喜欢

转载自blog.csdn.net/qq_59076775/article/details/126863353