javascript對文字進行關鍵字過濾
阿新 • • 發佈:2019-01-03
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>對文字內容進行關鍵詞過濾</title> </head> <body> <textarea cols="100" rows="6" id="filter"></textarea> <script> window.onload=function(){ var filter=document.getElementById("filter"), keywords=["javascript","美女",/[外]{1}.{0,3}[掛]{1}/], keywordslen=keywords.length; filter.onkeyup=function(){ for(var i=0;i<keywordslen;i++){ filter.value=filter.value.replace(keywords[i],"*"); } } } </script> </body> </html>