• javascript 压缩空格代码演示


                                                                     压缩空格代码演示

    主要是讲解 压缩一个字符串两段空格 

            例如:javascript函数里的空格不论是这样     var s = "Hello World        "; 

                                    这样        var s = "       Hello World"; 

                                     这样       var s = "     Hello World       "; 

                                     还是这样            var s = "  Hello World                "; 

              为了更加明显观察字符串后面空格效果

                            我们在取出结果的时候这样写  alert(Trim(s)+".....")     给函数Trim(s)加上了.....

                            经过压缩空格之后都是这样效果

                                                    

                                              

                                                     

     代码如下:

    <title>无标题文档</title>
    </head>
    
    <body>
    </body>
    </html>
    <script language="javascript">
    //压缩字符串中的两端空格。
     function   Trim(m){   
      while((m.length>0)&&(m.charAt(0)==' '))   
      m   =   m.substring(1, m.length);   
      while((m.length>0)&&(m.charAt(m.length-1)==' '))   
      m = m.substring(0, m.length-1);   
      return m;   
     }
     
    var s = "Hello World     ";
    alert(Trim(s)+".....")
    </script>
  • 相关阅读:
    php数组
    php运算符
    PHP数据类型
    面向对象3和继承
    面向对象2
    面向对象1
    语法整理php
    语法整理
    ajax
    数据库4
  • 原文地址:https://www.cnblogs.com/981971554nb/p/4254903.html
Copyright © 2020-2023  润新知