在div中限制100个最大字符,并在超过css或js时生成read more按钮

时间:2018-03-08 08:32:11

标签: jquery html css

这是我现有的工作。我将它限制为最多30个字符,但是当字符超出限制时,如何动态地添加更多链接到我的其他页面?我需要你的帮助。

var myDiv = $('.wwdtext');
myDiv.text(myDiv.text().substring(0,30))

<div style="background-color:#FF6201;width:220px;height:220px">
    <div class="wwdtext">Hello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello World</div>
</div>

1 个答案:

答案 0 :(得分:0)

&#13;
&#13;
var myDiv = $('.wwdtext');
myDiv.text(myDiv.text().substring(0,100))
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div style="background-color:#FF6201;width:220px;height:220px">
    <div class="wwdtext">Hello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldeqwrewqjkfbsajHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldeqwrewqjkfbsajHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello Worldeqwrewqjkfbsaj</div>
</div>
&#13;
&#13;
&#13;