2

我将此 jquery 插件用于“查看更多”文本:

http://keith-wood.name/moreRef.html

我从 tinymce 编辑器 html 文本保存到 mysql 数据库中。然后我在 php 页面中显示 html 文本,并使用“查看更多”文本 jquery 插件仅显示 100 个单词的文本。

我的问题是该插件不保留 html 格式的文本,但它将 html 格式的文本更改为简单文本,它删除了 html 标记。

如何保留带有 html 标记的文本以正确显示格式文本并且还有“查看更多”链接?

4

1 回答 1

0

您可以使用纯 css 来完成,并将 html 保留在适当的位置。这里是一个JS fiddle(IE6,7,8上不会显示越来越少,内容会被展开)

http://jsfiddle.net/6sj4e/45/

.text {
    height: 50px;
    overflow: hidden;
    height: 100%\9;
  }

input.less-more,
input.less-more:checked ~ label.more,
input.less-more:not(:checked) ~ label.less {
    display: none;
}

和 html :

<input id="chbox" class="less-more" type="checkbox">
<div class="text">Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius. Claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium lectorum. Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis per seacula quarta decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum.</div>
<label for="chbox" class='more'>more</label>
<label for="chbox" class='less'>less</label>
于 2014-04-17T10:22:36.157 回答