过滤敏感词。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script>
var str = ' 就OK花多少佛后进生的佛湖就是打工i护额武功i好喂狗i和购物活动刚回家哦二狗护额跟我互了空间都说过了空间都该睡觉了黄色灯光。';
var reg = /空间|黄色灯光/g;
document.write(str.replace(reg,function(s){
var tmp = '';
for(var i = 0; i < s.length; i++){
tmp+='*';
}
return '<span style="color: #c00">'+tmp+'</span>';
}));
</script>
</head>
<body>
</body>
</html>
格式整理。
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <script> window.onload = function(){ var oBtn = document.getElementById('btn'); var oTxt1 = document.getElementById('txt1'); var oTxt2 = document.getElementById('txt2'); oBtn.onclick = function(){ oTxt2.value=oTxt1.value.replace(/$/mg,'assdd'); } } </script> </head> <body> <textarea name="" id="txt1" cols="30" rows="10"></textarea> <input type="button" value="整理" id="btn"> <textarea name="" id="txt2" cols="30" rows="10"></textarea> </body> </html>