- <script>
- //供使用者调用
- function trim(s){
- return trimRight(trimLeft(s));
- }
- //去掉左边的空白
- function trimLeft(s){
- if(s == null) {
- return "";
- }
- var whitespace = new String(" /t/n/r");
- var str = new String(s);
- if (whitespace.indexOf(str.charAt(0)) != -1) {
- var j=0, i = str.length;
- while (j < i && whitespace.indexOf(str.charAt(j)) != -1){
- j++;
- }
- strstr = str.substring(j, i);
- }
- return str;
- }
- //去掉右边的空白
- function trimRight(s){
- if(s == null) return "";
- var whitespace = new String(" /t/n/r");
- var str = new String(s);
- if (whitespace.indexOf(str.charAt(str.length-1)) != -1){
- var i = str.length - 1;
- while (i >= 0 && whitespace.indexOf(str.charAt(i)) != -1){
- i--;
- }
- strstr = str.substring(0, i+1);
- }
- return str;
- }
- //检查tag的空格
- function dotag()
- {
- document.form1.tag.value = trim(document.form1.tag.value.replace(new RegExp(',',"gm"),','));
- document.form1.tag.value = trim(document.form1.tag.value.replace(new RegExp(' ',"gm"),','));
- document.form1.tag.value = trim(document.form1.tag.value.replace(new RegExp(',+',"gm"),','));
- }
- </script>
- <form name="form1">
- <input name="tag" type="text" id="tag" style="width:300px" value="" onBlur="dotag()">
- </form>
新闻热点
疑难解答