<asp:TextBox ID="systemdescribe" Width="160px" 
                 Text='<%# Eval("SystemDescribe") %>' runat="server" TextMode="MultiLine" 
                 Height="100px"></asp:TextBox>
我想设定一行又15个字就换行,这是固定的 ,怎么用JS写这样的脚本?

解决方案 »

  1.   

    用个投机取巧的方法,自己不断调试(改变textbox的width),直到width刚好够15个字,然后其他的就会自动换行了
      

  2.   


    随便写了个函数,你测度下吧 public string FormatTitle(string input, int maxLength)
        {
            if (input == "")
                return "";        string returnValue = null;
            int counter = 0;
            int ascIICharNum = maxLength * 2;       
            StringBuilder buffer = new StringBuilder();
            char[] sourceArr = input.ToCharArray();        foreach (char c in sourceArr)
            {
                if ((int)c > 255)
                {
                    counter += 2;
                }
                else
                {
                    counter++;
                }
                buffer.Append(c);            if (counter >= ascIICharNum)
                {
                     returnValue += buffer.ToString() + "<br>"; //如果是<asp:TextBox 之类,可以将<br>换成\r\n之类
                     buffer.Remove(0,buffer.Length);
                     counter = 0;
                }
            }        returnValue += buffer.ToString();        return returnValue;
        } <asp:Literal ID="Literal1" Text='<%# FormatTitle(((string)DataBinder.Eval(Container.DataItem,"SystemDescribe")),3) %>' runat="server"></asp:Literal>
    3为截取长度