Blogger Information
Blog 32
fans 1
comment 0
visits 29016
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
js实现自动聊天功能之敏感词过滤
艾克的博客
Original
1145 people have browsed it

<!DOCTYPE html>
<html lang="en">
<head>
   <meta charset="UTF-8">
   <title>聊天窗口实现</title>
   <style>
       #box {
           width: 300px;
           height: 300px;
           background-color: wheat;
       }
       #text {
           width: 230px;
           height: 60px;
           background-color: green;
           font-size: 1.2em;
       }
       button {
           width: 70px;
           height: 50px;
           background-color: red;
       }
   </style>
</head>
<body>
     <h1>聊天窗口</h1>
     <div id="box"></div>
     <input type="text" id="text" value="">
     <button id="btn">提交</button>
     <script>
         var box = document.getElementById('box')//获取聊天窗口内容
var text = document.getElementById('text')//获取文本内容
var btn = document.getElementById('btn')//获取提交按钮

         //添加点击事件onclick
btn.onclick = function () {
             var str1 = '<span>西门庆:</span>'
var str2 = '<span>潘金莲:</span>'
var innerHTML = [//做一个敏感词过滤词的数组
'他妈的'
];
             for (var i=0;i<innerHTML.length;i++){
                 text.value=text.value.replace(innerHTML[i],'***')//replace替换当前
}
             box.innerHTML += str1+text.value + '<br>'//将文本内容发送到聊天窗口
             
var bb = box.innerHTML += str2+'bb'+ '<br>'
text.value=''//清空文本框
}
     </script>
</body>
</html>



Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post