<script> window.onload = function(){ var oTxt1 = document.getElementById("txt1"); var oTxt2 = document.getElementById("txt2"); var oBtn = document.getElementById("btn"); oBtn.onclick = function(){ var reg = /北京|淘宝|百度/g; oTxt2.value = oTxt1.value.replace(reg,'***'); } } </script>
<textarea id="txt1" name="" rows="" cols=""></textarea><br /> <input id="btn" type="button" value="过滤" /><br /> <textarea id="txt2" name="" rows="" cols=""></textarea>