在html textarea中查找行数 [英] Finding number of lines in an html textarea

查看:298
本文介绍了在html textarea中查找行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个移动网络应用程序,其中滚动条未显示在设备的浏览器上。由于这个原因,我试图动态修改textarea的高度以使其更大,但是我不知道有什么方法可以实际获得html textarea的行数。任何帮助将不胜感激!

编辑

现在我意识到它本身不是新行,而是实际的换行。所以当一行完成时,它将文本包装到下一行。看起来好像它是一条新线。任何方式来计算这些数量?感谢!

解决方案

我还没有尝试过使用本博客中讨论的函数,但您可能会发现它很有用。



http ://kirblog.idetalk.com/2010/03/calculating-cursor-position-in-textarea.html



基本上,如果您创建一个 div ,然后将文本复制到该div中,使用相同的宽度和字体特征,然后可以获取所需的信息,例如行数。这个例子中的行数很容易,因为如果你知道一行代码有多少像素,那么只需找到测试div的宽度,你就可以得到一个非常准确的想法,你的 textarea


I'm writing a mobile web application where scrollbars are not displayed on the device's browser. Due to this, I'm trying to dynamically modify the height of the textarea to make it bigger, however I don't know of any way to actually get the line count on an html textarea. Any help would be greatly appreciated!

EDIT

So I realize now that it's not newlines per se, but actual line wrapping. So when one line finishes it wraps the text to the next line. It appears as if it is a new line. Any way to count the number of these? Thanks!

解决方案

I haven't tried using the function discussed in this blog, but you may find it useful.

http://kirblog.idetalk.com/2010/03/calculating-cursor-position-in-textarea.html

Basically, if you create a div and then copy the text into that div, with the same width and font characteristics, you can then get the information you need, such as the number of lines. The number of lines in this example would be easy, in that if you know how many pixels high a single line would be, then just find the width of the test div and you can get a pretty accurate idea as to how many lines are in your textarea.

这篇关于在html textarea中查找行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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