我遇到了一个问题,找到并创建一个解决方案,使用JQuery显示更多/更少的功能,并在目标div中进行格式化。在下面的代码段中,当我的页面填写表单时,null项目会填充文本。在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>
提前感谢您的帮助!
答案 0 :(得分:2)
更新的答案:
如果它不必固定为150个字符并且可以基于div大小,则可以使用此插件:dotdotdot.frebsite.nl
原始回答: 这是一个工作小提琴:http://jsfiddle.net/manishie/mgz8tec0/
您需要替换:
var content = $(this).html();
使用:
var content = $(this).text();
当您获得字符数时,这将删除html标记。