js 过滤敏感词
<
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
>
作者:freddyhuang
出处:https://www.cnblogs.com/freddyhuang
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。