<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<style>
.readLess{ display:none;}
.conteMain{ border:1px solid #ddd; background:#f5f5f5; padding:10px; font:normal 14px Arial, Helvetica, sans-serif;}
#conteMain p{ margin:0; padding:0;}
.readLess,.readMore{ background:#3CF; color:#fff; padding:5px 10px; width:80px; margin:10px 0px; cursor:pointer}
.readLess:hover,.readMore:hover{ background:#090}
</style>
</head>
<body>
<div class="conteMain">
<div id="conteMain">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. 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.<br>
<br>
<p>vived 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 </p><br>
<p>vived 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 </p><br>
<p>vived 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 </p><br>
<p>vived 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 </p><br>
<div>ved 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 l</div><br>
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>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
var conte = $("#conteMain").text().length;
var conte1 = $("#conteMain").text();
var bx1 = conte1.slice('',200);
if(conte > 200){
$("#conteMain").after("<span class='moreC'>"+ bx1 +"</span>"+"<div class='readMore'>Read More</div><div class='readLess'>Read Less</div>");
$("#conteMain").css("display","none");
};
$(".readMore").click(function(){
$("#conteMain").slideDown("slow");
$(".moreC").css("display","none");
$(".readLess").css("display","block");
$(this).css("display","none");
});
$(".readLess").click(function(){
$("#conteMain").slideUp("slow");
$(".moreC").css("display","block");
$(".readMore").css("display","block");
$(this).css("display","none");
});
</script>
</body>
</html>
我已经改变了$(本)的.html( t.slice(0,minimize_character_count)+ ' ... '+' Read more' + “的'+ t.slice(minimize_character_count,TextContentLenght)+'&nbsp'+'Read less' ); 但它读取后不能正常工作,并开始显示阅读更多。请提供一些不会破坏现有脚本的内容。 – Rajan
我已编辑我的帖子。 –
即使修剪过的字符串也很难保持HTML,这是实际的问题。无法弄清楚这一点! – Rajan