下面是我的解决办法,但是最终答不到想要的效果
- 文章部分
<p>
In the browser
</p>
<p style="text-align:justify;">
<span style="font-size: 16px; line-height: 2; font-family: Tahoma; background-color: rgb(255, 229, 0);">
In conclusion, the polysaccharides from two seaweeds, Porphyra haitanensis and Enteromorpha prolifera changed significantly
fecal microbiota content among the three groups at all levels.
<strong>The results suggest that polysaccharide type</strong> and glycoside may contribute to shaping mice gut microbiota.
Furtherly, we will determent their effect on fecal microbiota in the treatment of certain diseases.
</span>
</p>
- JS 代码,代码的主要逻辑是对每个单词用 i 标签包含起来。
var p = $('p');
parseHTML(p);
function parseHTML(p) {
for (var i = 0, length = p.length; i < length; i++) {
var e = $(p[i]);
if (e.children().length == 0) {
e.html(function(index, oldHtml) {
return oldHtml.replace(/\b(\w+?)\b/g, '<i class="word">$1</i>')
});
e.click(function(event) {
if (event.target.tagName === 'I') {
alert(event.target.innerHTML);
}
});
} else {
parseHTML(e.children());
}
}
}
- 结果:如下图,由于图片太大,所以 blank 了。红框中的单词实现了 i 标签包含。但是蓝框中,确没有。
http://photo.weibo.com/1771131114/photos/large/photo_id/4243484310650850/album_id/3483606186757120