zoukankan      html  css  js  c++  java
  • 可以让无空格连续的字符换行的JS(名字好难取_!)

    可以避免因某一连续字符过长而使页面布局遭破坏。。。

    function SetWordNewLine(Words,MaxLength)
       { 
        var WordArray;
        WordArray=Words.split(" ");
        
        for(i=0;i<WordArray.length;i++)
        {
         if(WordArray[i].length>MaxLength)
         {
          WordArray[i]=GetWordSubString(WordArray[i],MaxLength);
         }

        }
        var ResultWord="";
        for(i=0;i<WordArray.length;i++)
        {
         ResultWord+=WordArray[i]+" ";
        }
        return ResultWord;
       }
       
       //递归截取字符串
       function GetWordSubString(_Words,_MaxLength)
       {
        if(_Words.length>_MaxLength)
        {

         return _Words.substring(0,_MaxLength)+"<p style=\"margin-top:0px; margin-bottom:0px;\"/>"+GetWordSubString(_Words.substring(_MaxLength,_Words.length),_MaxLength);
        }
        else
        {
         return _Words+"<p style=\"margin-top:0px; margin-bottom:0px;\"/>";
        }
       }

  • 相关阅读:
    Mysql探索之索引详解,又能和面试官互扯了~
    POJ 1163
    POJ 1157
    POJ 1143
    POJ 1164
    HDU 2553
    POJ 1321
    POJ 1125
    POJ 2488
    POJ 3083
  • 原文地址:https://www.cnblogs.com/Random/p/889639.html
Copyright © 2011-2022 走看看