我遇到了一个问题,找到并创建了一个解决方案,使用JQuery在目标div中设置格式,从而显示更多/更少的功能。在下面的片段中,当填充我的页面的表单时,空项将填充文本。在150个可见的文本字符(忽略格式和标签),显示更多/更少的功能需要启动和隐藏大于150个字符的链接,以显示或多或少。
我尝试过使用这个http://code-tricks.com/jquery-read-more-less-example/作为基础,但是在使用带有标记的div代码时遇到了困难。
<div class="search-keywords more">
<p style="display: none;" id="searchCriteria">All records</p>
<p style="display: inline;" id="emEnvSubclass">EM Environmental Subclass = </p>
<p style="display: inline; font-style: italic;" id="emEnvSubclassValue">Atomsphere OR Created Greenspace OR Forests</p>
<p style="display: inline;" id="emSourceColl"> AND EM Source/Collection = </p>
<p style="display: inline; font-style: italic;" id="emSourceCollValue">Other OR US EPA</p>
<p style="display: none;" id="cicesSec">null</p>
<p style="display: none; font-style: italic;" id="cicesSecValue">null</p>
<p style="display: none;" id="fegsEnvSubclass">null</p>
<p style="display: none; font-style: italic;" id="fegsEnvSubclassValue">null</p>
</div>提前感谢您的帮助!
发布于 2014-09-17 03:07:13
更新答案:
如果它不必固定在150个字符,并且可以基于div大小,则可以使用以下插件:dotdotdot.frebsite.nl
原始答案:,这是一个有用的小提琴:http://jsfiddle.net/manishie/mgz8tec0/
你需要替换:
var content = $(this).html();通过以下方式:
var content = $(this).text();这将删除html标记时,您得到的字符数。
https://stackoverflow.com/questions/25879112
复制相似问题