[轉貼]JavaScript 去掉空格

          摘錄地址:http://www.mltang.com/article/efd65c8e-07f9-4c9b-8b6b-edab9a9b46a4.html

          //Javascript中為String對象添加trim
          String.prototype.Trim  = function(){return this.replace(/(^\s*)|(\s*$)/g, "");}
          String.prototype.LTrim = function(){return this.replace(/(^\s*)/g, "");}
          String.prototype.Rtrim = function(){return this.replace(/(\s*$)/g, "");}


          答3:
          <input type=text name=txt size=10><br>
          <input type=button value=check onclick="check1()">

          <script language="Javascript"><!--
          String.prototype.Trim  = function(){return this.replace(/(^\s*)|(\s*$)/g, "");}
          function check1(){
            var tt = document.all.txt.value;
            var s;
            if (tt.Trim().length==0){
               alert("輸入不能為空!");
               document.all.txt.value = "";
               return;}
            tt = tt.Trim();
            for (i = 0; i < tt.length; i++){
              s = tt.charCodeAt(i);
              if ((s==13) || (s==9)){
                 alert("你輸入的字符中含有tab或者回車鍵!");
                 document.all.txt.value = tt;
                 return; }
              }
            return;
            }
          // --></script>



          歡迎大家訪問我的個人網站 萌萌的IT人

          posted on 2007-04-23 13:51 見酒就暈 閱讀(820) 評論(0)  編輯  收藏 所屬分類: HTML

          <2025年6月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          導航

          統計

          常用鏈接

          留言簿(3)

          我參與的團隊

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          收藏夾

          BLOG

          FRIENDS

          LIFE

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 莫力| 永安市| 宾阳县| 那曲县| 东乡| 富平县| 蓬莱市| 绥棱县| 西昌市| 汶川县| 石家庄市| 云安县| 通江县| 鞍山市| 千阳县| 疏附县| 大厂| 昌黎县| 曲松县| 监利县| 汶川县| 临桂县| 泰来县| 汉阴县| 礼泉县| 洛阳市| 加查县| 弋阳县| 固阳县| 龙井市| 怀安县| 仪陇县| 曲水县| 正镶白旗| 华安县| 水富县| 且末县| 监利县| 措勤县| 天全县| 水城县|