jsはreplaceを利用して敏感な文字を除去します.(俗称の河蟹!!!)
4365 ワード
<!DOCTYPE HTML>
<html>
<head>
<title>please enter your title</title>
<meta charset="utf-8">
<meta name="Author" content=" ">
<style type='text/css'> *{ font-family:'Microsoft yahei'; } </style>
</head>
<body>
<input type="text" id="txt" /> <input type="button" id="btn" value=" " />
<div id="box"></div>
<script type="text/javascript"> var oTxt = document.getElementById('txt'); var oBtn = document.getElementById('btn'); var oBox = document.getElementById('box'); var reg = / | | /g; oBtn.onclick = function(){ var val = oTxt.value; oTxt.value = ''; if ( val ) { var oP = document.createElement('p'); val = val.replace(reg, function( $0 ){ alert($0); /* reg g $0: $1: 1 $2: 2 $3: 3 ... */ var r = ''; for ( var i=0;i<$0.length;i++ ) { r += '*'; } return r; }); oP.innerHTML = val; oBox.appendChild( oP ); } } </script>
</body>
</html>