除空格以外,TextArea还会包装哪些字符? [英] What characters will a TextArea wrap at, other than spaces?

查看:27
本文介绍了除空格以外,TextArea还会包装哪些字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发插件的最新版本Textarea Line Counter( http://mostthingsweb.com/?p = 84 ).为了使它更加准确,我想确定换行的文本区域,因为它们太大而无法容纳在行上(如一系列重复的字符).

I'm working on the latest version of my plugin, Textarea Line Counter (http://mostthingsweb.com/?p=84). To make it even more accurate, I want to identify regions of text that wrap because they are too large to fit on the line (like a sequence of repeated characters).

我假设浏览器仅在空格处包装文本.还有其他可以换行的字符吗?谢谢

I'm assuming that browsers only wrap text at spaces. Are there any other characters that lines can be wrapped at? Thank you,

推荐答案

根据您的所有建议,我创建了一个解决方案.它相当大,实际上我想我会将它制作成一个单独的插件,并将其包含在我的Textarea Line Counter中.它是这样的:

Based on all your advice, I have created a solution. It is rather large, and in fact I think I will make it into a separate plugin, as well as including it in my Textarea Line Counter. It works like this:

  1. 创建一个 div 作为容器,并将字体设置为等距的字体(即,每个字符的宽度相同)
  2. 在容器内创建一个 span ,并放置一个字母.
  3. 进行跨度的宽度测量(一旦克隆了边距,填充和其他一些CSS属性,该宽度即为字母的宽度)
  4. 在容器中创建另一个div并克隆其CSS属性.将其宽度设置为步骤3中找到的字母的宽度的两倍,并记录其高度.
  5. 要测试字符是否会引起换行,请将 div 的文本设置为: A [some character] A . [某些字符] 是您要测试的字符.
  6. 测试 div 的高度.如果它大于在步骤4中找到的高度,则文本将自动换行.
  1. Create a div to act as a container, and set the font to something monospaced (i.e. every character is the same width)
  2. Create a span within the container, and place a single letter.
  3. Take the width measurement of the span (which will be the width of the letter, once margins, padding, and some other CSS attributes are cloned)
  4. Create another div within the container and clone its CSS attributes. Set it's width to be two times the width of the letter found in step 3, and record its height.
  5. To test if a character will cause a wrap, set the text of the div to: A[some character]A. [some character] is a character you are trying to test.
  6. Test the height of the div. If it is larger than the height found in step 4, the text has wrapped.

我期待发布此插件.再次感谢您的所有建议.

I'm looking forward to releasing this plugin. Thank you again for all your advice.

这篇关于除空格以外,TextArea还会包装哪些字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆