首頁  >  文章  >  web前端  >  JavaScript實作自動對頁面上敏感字進行屏蔽的方法_javascript技巧

JavaScript實作自動對頁面上敏感字進行屏蔽的方法_javascript技巧

WBOY
WBOY原創
2016-05-16 15:48:471994瀏覽

本文實例講述了JavaScript實作自動對頁面上敏感字進行屏蔽的方法。分享給大家供大家參考。具體如下:

<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>

希望本文所述對大家的javascript程式設計有所幫助。

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn