[轉貼]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 見酒就暈 閱讀(821) 評論(0)  編輯  收藏 所屬分類: HTML

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

          導航

          統計

          常用鏈接

          留言簿(3)

          我參與的團隊

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          收藏夾

          BLOG

          FRIENDS

          LIFE

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 界首市| 黄梅县| 惠东县| 奉新县| 沈丘县| 湘潭市| 连城县| 南华县| 衡水市| 新乡市| 正蓝旗| 永福县| 呼图壁县| 监利县| 衡水市| 调兵山市| 开化县| 湘潭市| 微山县| 金乡县| 永川市| 永顺县| 进贤县| 阳泉市| 札达县| 宜城市| 肇州县| 海兴县| 施秉县| 新建县| 巴青县| 巩义市| 玉树县| 光山县| 班戈县| 澜沧| 福州市| 兴宁市| 庄河市| 金寨县| 红安县|