javascript - DIV 中的文本对齐(TEXT 没有空格)

标签 javascript jquery html css

如果我在 Textarea 中输入 Lengthy Text 没有空格 并且我附加它,它扰乱 DIV对齐 并且文本以单行 显示。如何在DIV中控制这种固定宽度的文字?

这是我的演示:

http://jsfiddle.net/YRKxR/29/

也看看这张图片,只是想以更好的方式解释我的问题。

enter image description here

我也在这里提供代码或访问我的 JsFiddle DEMO

这是我的 HTML:

<table border="0" width="500" cellspacing="0">
   <tbody class="append_data"></tbody>

<tr>
  <td> 
      <textarea name="description" id="description"></textarea>
      <p>
          <a href="javascript:void(0);" class="add_more">Add More</a>
      </p>
  </td> 
</tr> 

</table> 

这是 CSS:

#description{
    width:400px;    
}

.description_text{
    border:#333333 solid 1px;
    width:400px !important;
}

这是我的 JS 代码:

$('.add_more').click(function()
                     {
                        var description = $('#description').val();
                        $(".append_data").append('<div class="description_text">'+description+'</div><br><br>');
                     });

最佳答案

您可能希望将文本包装在 div 中:

CSS:

#description{
    width:400px;    
}

.description_text{
    border:#333333 solid 1px;
    width:400px !important;
}

.append_data{
   white-space: pre-wrap;      /* CSS3 */   
   white-space: -moz-pre-wrap; /* Firefox */    
   white-space: -pre-wrap;     /* Opera <7 */   
   white-space: -o-pre-wrap;   /* Opera 7 */    
   word-wrap: break-word;      /* IE */
}

http://jsfiddle.net/7jE9p/

关于javascript - DIV 中的文本对齐(TEXT 没有空格),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18829848/

相关文章:

javascript - 如何在使用 jquery/javascript 单击 div 时将字符添加到文本框

jquery - Bootstrap 折叠导航栏切换不起作用

javascript - 抛出错误时不调用 Jasmine afterAll

javascript - 填充文本不起作用

javascript - jQuery setTimeout 不起作用

使用 JSF 的 JQuery 日期选择器

javascript - 使用第三方应用程序构建我的网站文件

javascript - 在嵌套对象上实现代理

javascript - 使用 Angularjs 将动态数据从 Json 获取到 Html

html - 一个页面上的多个仅 HTML/CSS slider 不会独立更改