问题描述
让我们说我有以下标记:
Lets say I have the following markup:
<html>
<head>
<title>Page Title</title>
</head>
<body>
<h1>Some title</h1>
<p>First paragraph</p>
<p>Second paragraph</p>
</body>
<html>
我需要标记文本的某些部分,即第一段secon"看起来像这样:
I need to mark some parts of the text, namely "irst paragraph secon"It would look something like this:
<html>
<head>
<title>Page Title</title>
</head>
<body>
<h1>Some title</h1>
<p>F
<mark>
irst paragraph</p><p>Secon
</mark>
d paragraph</p>
</body>
<html>
但是问题是html标记将被破坏.标记越复杂,这种方法就会遇到的问题越多.
But the problem is be the html markup would be broken. The more complex the markup, the more problems this approach would have.
问题:
寻找有关如何使用第一个HTML示例并应用函数以返回html结构的想法,在该结构中以某种方式专门标记了第一段第二段".
Looking for ideas on how can I take the first HTML example and apply a function to return a html structure where "irst paragraph second" is specifically marked somehow.
我目前拥有的是:
- 字符串第一段"的父容器
- 第一段第二段"文字
- 第一段"中文本"irst"的偏移量
推荐答案
如果要突出显示文档中的文本,则此插件将对您有所帮助.
If you want to highlight text in a document then this plug-in will be helpful for you.
https://github.com/julmot/jquery.mark
小提琴示例: https://jsfiddle.net/julmot/vpav6tL1/
用法很简单:
$(".context").mark("keyword");
这篇关于在html文件中标记文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!