Home > Web Front-end > JS Tutorial > body text

JavaScript method to automatically block sensitive words on the page_javascript skills

WBOY
Release: 2016-05-16 15:48:47
Original
2027 people have browsed it

The example in this article describes how JavaScript can automatically block sensitive words on the page. Share it with everyone for your reference. The details are as follows:

<html>
<head>
 <title>Bad Words Example</title>
 <script type="text/javascript">
   function filterText(sText) {
    var reBadWords = /badword|anotherbadword/gi;
    return sText.replace(reBadWords, "****");
   }
   function showText() {
    var oInput1 = document.getElementById("txt1");
    var oInput2 = document.getElementById("txt2");
    oInput2.value = filterText(oInput1.value);
   }
 </script>
</head>
<body>
 <P>
 <textarea rows="10" cols="50" id="txt1">badword anotherbadword</textarea><br />
 <input type="button" value="Filter Bad Words" onclick="showText()" /></p>
 <P>Filtered Text:<br />
 <textarea rows="10" cols="50" id="txt2"></textarea></p>
</body>
</html>
Copy after login

I hope this article will be helpful to everyone’s JavaScript programming design.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!