如何检测单词换行的位置
我想在网站中显示的每行文本的开头添加“span”标签,并在末尾添加“/span”标签,并在调整包含此类文本的 div 大小时动态更改它。问题是我不知道如何检测文本的换行位置 - 如果我有这样的信息,那就很容易了。所以我的问题是:有没有办法使用 javascript 确定文本的换行位置? 我找到了一个 javascript 库,它可以对网站中的文本进行连字符,但我不确定它如何检测换行。工作示例位于此处,可以找到其源代码此处。
I would like to add 'span' tag on the beginning and '/span' on the end of each line of text as it is presented in the website and change it dynamically when a div containing such text is resized. The problem is that I don't know how to detect where the text is being wrapped - if I had such information it would be easy. So my question is: is there a way to determine where the text is wrapped using javascript?
I have found a javascript library which hyphenates the text in the site but I'm not sure how does it detect line wraps. The working example is here and it's source can be found here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,这就像搜索并突出显示文本。
使用 javascript,您可以在这里学习:
搜索并突出显示文本
或此处:
how-can-i-use-jquery-to-style-parts-of-all-instances-of-a-specific-word
只需下载/保存网页即可学习。
yes, this is like to Search For and Highlight Text.
using javascript you can learn it here:
Search For and Highlight Text
or here:
how-can-i-use-jquery-to-style-parts-of-all-instances-of-a-specific-word
just download/save the web page there and you can learn it.