<body> <input type="text" name="CAL_COM_ID" id="CAL_COM_ID" onkeyup="cky(this)"/> <input type="text" name="CAL_COM_ID1" id="CAL_COM_ID1" onkeyup="value=value.replace(/[^(\(\)\d\&\|)]/g,'')"/> <script type="text/javascript"> function cky(obj) { var t = obj.value.replace(/[^(\(\)\d\&\|)]/g,""); if(obj.value!=t) obj.value=t; } </script> </body>
第一種寫法寫完后鍵盤左右鍵移動,光標可以移動;第二種寫法光標不能移動。項目中用了第一種寫法,特此記錄一下。