javascript - 如何仅使用单个 div 实现阅读更多功能

标签 javascript jquery html css

<div>This is my content containing some general large text to display ...
   Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,          when an unknown printer took a galley of type and scrambled it to make a type  specimen book. It has survived not only five centuries, but also the leap into  electronic typesetting, remaining essentially unchanged. It was popularised in  the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum</div>

如何在点击 (...) 时实现阅读更多扩展内容的功能 没有任何其他嵌套的 Div 或

标签“只是一个 Div”

提前致谢

最佳答案

做类似的事情:

HTML

<div class="truncate">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>

CSS

.truncate {
  width: 250px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

JavaScript

$(".truncate").click(function() {
    $(this).removeClass("truncate");
});

关于javascript - 如何仅使用单个 div 实现阅读更多功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28294404/

相关文章:

javascript - 通过切换或显示/隐藏切换 Div 内容

javascript - 如何使用 jquery 获取和更改值

Javascript 创建的按钮不会以 HTML 形式显示

html - 创建一个带有标签的垂直分隔符

html - CSS div 椭圆形

javascript - 在 Javascript 中对以下字符串进行子字符串化的最简单方法

javascript - 如果状态是某种东西,则执行 .filter 和 .map,否则仅执行 .map

javascript - Jquery .live 事件没有触发

javascript - 如何访问for循环内的子数组长度?

javascript - Extjs:如何使用网格行选择中的值填充表单